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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Buffer.fst | FStar.Buffer.create | val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init)) | val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init)) | let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 822,
"start_col": 0,
"start_line": 816
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | init: a -> len: FStar.UInt32.t -> FStar.HyperStack.ST.StackInline (FStar.Buffer.buffer a) | FStar.HyperStack.ST.StackInline | [] | [] | [
"FStar.UInt32.t",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Buffer.as_seq",
"FStar.Buffer.sel",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Buffer._buffer",
"FStar.Buffer.MkBuffer",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.reference",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.HyperStack.ST.salloc",
"FStar.Heap.trivial_preorder",
"FStar.Seq.Base.create",
"FStar.HyperStack.ST.mstackref"
] | [] | false | true | false | false | false | let create #a init len =
| let content:reference (lseq a (v len)) = salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get () in
assert (Seq.equal (as_seq h b) (sel h b));
b | false |
FStar.Buffer.fst | FStar.Buffer.index | val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n))) | val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n))) | let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 964,
"start_col": 0,
"start_line": 962
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b}
-> FStar.HyperStack.ST.Stack a | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"FStar.Buffer.lseq",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.HyperStack.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content"
] | [] | false | true | false | false | false | let index #a b n =
| let s = !b.content in
Seq.index s (v b.idx + v n) | false |
FStar.Buffer.fst | FStar.Buffer.to_seq_full | val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b )) | val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b )) | let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 956,
"start_col": 0,
"start_line": 953
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Buffer.buffer a -> FStar.HyperStack.ST.ST (FStar.Seq.Base.seq a) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Buffer.buffer",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__length",
"FStar.UInt.uint_t",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"FStar.Seq.Base.seq",
"FStar.Buffer.lseq",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.HyperStack.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content"
] | [] | false | true | false | false | false | let to_seq_full #a b =
| let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length) | false |
FStar.Buffer.fst | FStar.Buffer.rcreate | val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) | val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) | let rcreate #a r init len = rcreate_common r init len false | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 898,
"start_col": 0,
"start_line": 898
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.HyperHeap.rid -> init: a -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST (FStar.Buffer.buffer a) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.UInt32.t",
"FStar.Buffer.rcreate_common",
"FStar.Buffer.buffer"
] | [] | false | true | false | false | false | let rcreate #a r init len =
| rcreate_common r init len false | false |
FStar.Buffer.fst | FStar.Buffer.createL | val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b)) | val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b)) | let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 856,
"start_col": 0,
"start_line": 848
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | init: Prims.list a -> FStar.HyperStack.ST.StackInline (FStar.Buffer.buffer a) | FStar.HyperStack.ST.StackInline | [] | [] | [
"Prims.list",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Buffer.as_seq",
"FStar.Buffer.sel",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Buffer._buffer",
"FStar.Buffer.MkBuffer",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.reference",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.HyperStack.ST.salloc",
"FStar.Heap.trivial_preorder",
"FStar.Seq.Base.seq_of_list",
"FStar.HyperStack.ST.mstackref",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.length",
"FStar.UInt32.t",
"FStar.UInt32.uint_to_t"
] | [] | false | true | false | false | false | let createL #a init =
| let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content:reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get () in
assert (Seq.equal (as_seq h b) (sel h b));
b | false |
FStar.Buffer.fst | FStar.Buffer.rfree | val rfree (#a: Type) (b: buffer a)
: ST unit
(requires (fun h0 -> live h0 b /\ freeable b))
(ensures
(fun h0 _ h1 ->
is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) | val rfree (#a: Type) (b: buffer a)
: ST unit
(requires (fun h0 -> live h0 b /\ freeable b))
(ensures
(fun h0 _ h1 ->
is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) | let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 921,
"start_col": 0,
"start_line": 918
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Buffer.buffer a -> FStar.HyperStack.ST.ST Prims.unit | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Buffer.buffer",
"FStar.HyperStack.ST.rfree",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"FStar.Buffer.live",
"FStar.Buffer.freeable",
"Prims.b2t",
"FStar.Monotonic.HyperStack.is_mm",
"FStar.Buffer.max_length",
"FStar.Buffer.content",
"FStar.HyperStack.ST.is_eternal_region",
"FStar.Buffer.frameOf",
"Prims.eq2",
"FStar.Monotonic.HyperStack.free"
] | [] | false | true | false | false | false | let rfree (#a: Type) (b: buffer a)
: ST unit
(requires (fun h0 -> live h0 b /\ freeable b))
(ensures
(fun h0 _ h1 ->
is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) =
| rfree b.content | false |
FStar.Buffer.fst | FStar.Buffer.rcreate_common | val rcreate_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (mm: bool)
: ST (buffer a)
(requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) | val rcreate_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (mm: bool)
: ST (buffer a)
(requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) | let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 889,
"start_col": 8,
"start_line": 876
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.HyperHeap.rid -> init: a -> len: FStar.UInt32.t -> mm: Prims.bool
-> FStar.HyperStack.ST.ST (FStar.Buffer.buffer a) | FStar.HyperStack.ST.ST | [] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"FStar.UInt32.t",
"Prims.bool",
"Prims.unit",
"FStar.Buffer.lemma_upd",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Buffer.as_seq",
"FStar.Buffer.sel",
"FStar.Buffer.buffer",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Buffer._buffer",
"FStar.Buffer.MkBuffer",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.reference",
"FStar.HyperStack.ST.ralloc_mm",
"FStar.Heap.trivial_preorder",
"FStar.HyperStack.ST.mmmref",
"FStar.HyperStack.ST.ralloc",
"FStar.HyperStack.ST.mref",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"FStar.HyperStack.ST.is_eternal_region",
"Prims.l_and",
"FStar.Buffer.rcreate_post_common",
"Prims.eq2",
"FStar.Monotonic.HyperStack.is_mm",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Buffer.__proj__MkBuffer__item__content"
] | [] | false | true | false | false | false | let rcreate_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (mm: bool)
: ST (buffer a)
(requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) =
| let h0 = HST.get () in
let s = Seq.create (v len) init in
let content:reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in
let b = MkBuffer len content 0ul len in
let h1 = HST.get () in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b | false |
FStar.Buffer.fst | FStar.Buffer.lemma_aux_0 | val lemma_aux_0
(#a: Type)
(b: buffer a)
(n: UInt32.t{v n < length b})
(z: a)
(h0: mem)
(tt: Type)
(bb: buffer tt)
: Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures
(live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))) | val lemma_aux_0
(#a: Type)
(b: buffer a)
(n: UInt32.t{v n < length b})
(z: a)
(h0: mem)
(tt: Type)
(bb: buffer tt)
: Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures
(live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))) | let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm () | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 975,
"start_col": 8,
"start_line": 968
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} ->
z: a ->
h0: FStar.Monotonic.HyperStack.mem ->
tt: Type0 ->
bb: FStar.Buffer.buffer tt
-> FStar.Pervasives.Lemma
(requires FStar.Buffer.live h0 b /\ FStar.Buffer.live h0 bb /\ FStar.Buffer.disjoint b bb)
(ensures
FStar.Buffer.live h0 b /\ FStar.Buffer.live h0 bb /\
(let h1 =
FStar.Monotonic.HyperStack.upd h0
(MkBuffer?.content b)
(FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z)
in
FStar.Buffer.as_seq h0 bb == FStar.Buffer.as_seq h1 bb)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Monotonic.HyperStack.mem",
"FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_mm",
"Prims.unit",
"FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_preorders",
"Prims.l_and",
"FStar.Buffer.live",
"FStar.Buffer.disjoint",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Buffer.as_seq",
"FStar.Monotonic.HyperStack.upd",
"FStar.Buffer.lseq",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.Seq.Base.upd",
"FStar.Buffer.sel",
"Prims.op_Addition",
"FStar.Buffer.idx",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_aux_0
(#a: Type)
(b: buffer a)
(n: UInt32.t{v n < length b})
(z: a)
(h0: mem)
(tt: Type)
(bb: buffer tt)
: Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures
(live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))) =
| Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm () | false |
FStar.Buffer.fst | FStar.Buffer.lemma_aux | val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] | val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] | let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 1006,
"start_col": 0,
"start_line": 1006
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} ->
z: a ->
h0: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b)
(ensures
FStar.Buffer.live h0 b /\
FStar.Buffer.modifies_1 b
h0
(FStar.Monotonic.HyperStack.upd h0
(MkBuffer?.content b)
(FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z)
))
[
SMTPat (FStar.Monotonic.HyperStack.upd h0
(MkBuffer?.content b)
(FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z)
)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Monotonic.HyperStack.mem",
"FStar.Buffer.lemma_aux_2",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_aux #a b n z h0 =
| lemma_aux_2 b n z h0 | false |
FStar.Buffer.fst | FStar.Buffer.to_seq | val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) )) | val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) )) | let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 945,
"start_col": 0,
"start_line": 942
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Buffer.buffer a -> l: FStar.UInt32.t{FStar.UInt32.v l <= FStar.Buffer.length b}
-> FStar.HyperStack.ST.STL (FStar.Seq.Base.seq a) | FStar.HyperStack.ST.STL | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.UInt.uint_t",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"FStar.Seq.Base.seq",
"FStar.Buffer.lseq",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.HyperStack.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content"
] | [] | false | true | false | false | false | let to_seq #a b l =
| let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l) | false |
FStar.Buffer.fst | FStar.Buffer.lemma_aux_1 | val lemma_aux_1 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type)
: Lemma (requires (live h0 b))
(ensures
(live h0 b /\
(forall (bb: buffer tt).
(live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))) | val lemma_aux_1 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type)
: Lemma (requires (live h0 b))
(ensures
(live h0 b /\
(forall (bb: buffer tt).
(live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))) | let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 986,
"start_col": 8,
"start_line": 978
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} ->
z: a ->
h0: FStar.Monotonic.HyperStack.mem ->
tt: Type0
-> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b)
(ensures
FStar.Buffer.live h0 b /\
(forall (bb: FStar.Buffer.buffer tt).
FStar.Buffer.live h0 bb /\ FStar.Buffer.disjoint b bb ==>
(let h1 =
FStar.Monotonic.HyperStack.upd h0
(MkBuffer?.content b)
(FStar.Seq.Base.upd (FStar.Buffer.sel h0 b)
(FStar.Buffer.idx b + FStar.UInt32.v n)
z)
in
FStar.Buffer.as_seq h0 bb == FStar.Buffer.as_seq h1 bb))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Monotonic.HyperStack.mem",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Prims.l_and",
"FStar.Buffer.live",
"FStar.Buffer.disjoint",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Buffer.as_seq",
"FStar.Monotonic.HyperStack.upd",
"FStar.Buffer.lseq",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.Seq.Base.upd",
"FStar.Buffer.sel",
"Prims.op_Addition",
"FStar.Buffer.idx",
"FStar.Classical.move_requires",
"FStar.Buffer.lemma_aux_0",
"Prims.unit",
"Prims.squash",
"Prims.l_Forall",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_aux_1 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type)
: Lemma (requires (live h0 b))
(ensures
(live h0 b /\
(forall (bb: buffer tt).
(live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))) =
| let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) | false |
FStar.Buffer.fst | FStar.Buffer.offset | val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'}) | val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'}) | let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 62,
"end_line": 1072,
"start_col": 0,
"start_line": 1071
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
i:
FStar.UInt32.t
{ FStar.UInt32.v i + FStar.UInt32.v (MkBuffer?.idx b) < Prims.pow2 FStar.UInt32.n /\
FStar.UInt32.v i <= FStar.UInt32.v (MkBuffer?.length b) }
-> b': FStar.Buffer.buffer a {FStar.Buffer.includes b b'} | Prims.Tot | [
"total"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"Prims.pow2",
"FStar.UInt32.n",
"Prims.op_LessThanOrEqual",
"FStar.Buffer.__proj__MkBuffer__item__length",
"FStar.Buffer.MkBuffer",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.UInt32.op_Plus_Hat",
"FStar.UInt32.op_Subtraction_Hat",
"FStar.Buffer.includes"
] | [] | false | false | false | false | false | let offset #a b i =
| MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) | false |
FStar.Buffer.fst | FStar.Buffer.upd | val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) | val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) | let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 1021,
"start_col": 0,
"start_line": 1013
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Buffer.buffer a -> n: FStar.UInt32.t -> z: a -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"FStar.Seq.Properties.upd_slice",
"FStar.Buffer.idx",
"Prims.op_Addition",
"FStar.Buffer.length",
"FStar.UInt32.v",
"Prims.unit",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"FStar.Seq.Base.slice",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Buffer.lemma_aux",
"FStar.HyperStack.ST.op_Colon_Equals",
"FStar.Buffer.lseq",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"FStar.HyperStack.ST.op_Bang"
] | [] | false | true | false | false | false | let upd #a b n z =
| let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get () in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z | false |
FStar.Buffer.fst | FStar.Buffer.lemma_sub_spec' | val lemma_sub_spec'
(#a: Type)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t{v len <= length b /\ v i + v len <= length b})
(h: _)
: Lemma (requires (live h b))
(ensures
(live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))] | val lemma_sub_spec'
(#a: Type)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t{v len <= length b /\ v i + v len <= length b})
(h: _)
: Lemma (requires (live h b))
(ensures
(live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))] | let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 1066,
"start_col": 0,
"start_line": 1058
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
i: FStar.UInt32.t ->
len:
FStar.UInt32.t
{ FStar.UInt32.v len <= FStar.Buffer.length b /\
FStar.UInt32.v i + FStar.UInt32.v len <= FStar.Buffer.length b } ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma (requires FStar.Buffer.live h b)
(ensures
FStar.Buffer.live h (FStar.Buffer.sub b i len) /\
FStar.Buffer.as_seq h (FStar.Buffer.sub b i len) ==
FStar.Seq.Base.slice (FStar.Buffer.as_seq h b)
(FStar.UInt32.v i)
(FStar.UInt32.v i + FStar.UInt32.v len))
[SMTPat (FStar.Buffer.live h (FStar.Buffer.sub b i len))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"Prims.op_Addition",
"FStar.Monotonic.HyperStack.mem",
"FStar.Buffer.lemma_sub_spec",
"Prims.unit",
"FStar.Buffer.live",
"Prims.squash",
"FStar.Buffer.sub",
"Prims.eq2",
"FStar.Seq.Base.seq",
"FStar.Buffer.as_seq",
"FStar.Seq.Base.slice",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_sub_spec'
(#a: Type)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t{v len <= length b /\ v i + v len <= length b})
h
: Lemma (requires (live h b))
(ensures
(live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))] =
| lemma_sub_spec b i len h | false |
FStar.Buffer.fst | FStar.Buffer.op_Array_Access | val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n))) | val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n))) | let op_Array_Access #a b n = index #a b n | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 1140,
"start_col": 0,
"start_line": 1140
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 | b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b}
-> FStar.HyperStack.ST.Stack a | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Buffer.index"
] | [] | false | true | false | false | false | let ( .() ) #a b n =
| index #a b n | false |
FStar.Buffer.fst | FStar.Buffer.sub | val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) | val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) | let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 1028,
"start_col": 0,
"start_line": 1026
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
i: FStar.UInt32.t ->
len: FStar.UInt32.t{FStar.UInt32.v i + FStar.UInt32.v len <= FStar.Buffer.length b}
-> b':
FStar.Buffer.buffer a
{FStar.Buffer.includes b b' /\ FStar.Buffer.length b' == FStar.UInt32.v len} | Prims.Tot | [
"total"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Buffer.MkBuffer",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.UInt32.op_Plus_Hat",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"Prims.unit",
"Prims._assert",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.UInt32.n",
"Prims.l_and",
"FStar.Buffer.includes",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size"
] | [] | false | false | false | false | false | let sub #a b i len =
| assert (v i + v b.idx < pow2 n);
MkBuffer b.max_length b.content (i +^ b.idx) len | false |
FStar.Buffer.fst | FStar.Buffer.split | val split (#t: _) (b: buffer t) (i: UInt32.t{v i <= length b}) : Tot (buffer t * buffer t) | val split (#t: _) (b: buffer t) (i: UInt32.t{v i <= length b}) : Tot (buffer t * buffer t) | let split #t (b:buffer t) (i:UInt32.t{v i <= length b}) : Tot (buffer t * buffer t)
= sub b 0ul i, offset b i | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 1216,
"start_col": 0,
"start_line": 1215
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma
(requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2))
(ensures (modifies_one (frameOf b) h0 h2))
[SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)]
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(** Corresponds to memcpy *)
val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) ==
Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) ))
let rec blit #t a idx_a b idx_b len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
blit #t a idx_a b idx_b len';
let z = a.(idx_a +^ len') in
b.(idx_b +^ len') <- z;
let h1 = HST.get() in
Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len');
Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b));
Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b))
end
(** Corresponds to memset *)
val fill: #t:Type
-> b:buffer t
-> z:t
-> len:UInt32.t{v len <= length b}
-> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z
/\ Seq.slice (as_seq h1 b) (v len) (length b) ==
Seq.slice (as_seq h0 b) (v len) (length b) ))
let rec fill #t b z len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
fill #t b z len';
b.(len') <- z;
let h = HST.get() in
Seq.snoc_slice_index (as_seq h b) 0 (v len');
Seq.lemma_tail_slice (as_seq h b) (v len') (length b)
end;
let h1 = HST.get() in
Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Buffer.buffer t -> i: FStar.UInt32.t{FStar.UInt32.v i <= FStar.Buffer.length b}
-> FStar.Buffer.buffer t * FStar.Buffer.buffer t | Prims.Tot | [
"total"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Buffer.sub",
"FStar.UInt32.__uint_to_t",
"FStar.Buffer.offset",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let split #t (b: buffer t) (i: UInt32.t{v i <= length b}) : Tot (buffer t * buffer t) =
| sub b 0ul i, offset b i | false |
FStar.Buffer.fst | FStar.Buffer.lemma_offset_spec | val lemma_offset_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
(h: _)
: Lemma (requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[
SMTPatOr
[[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]
] | val lemma_offset_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
(h: _)
: Lemma (requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[
SMTPatOr
[[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]
] | let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 88,
"end_line": 1081,
"start_col": 0,
"start_line": 1074
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
i:
FStar.UInt32.t
{ FStar.UInt32.v i + FStar.UInt32.v (MkBuffer?.idx b) < Prims.pow2 FStar.UInt32.n /\
FStar.UInt32.v i <= FStar.UInt32.v (MkBuffer?.length b) } ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(ensures
FStar.Buffer.as_seq h (FStar.Buffer.offset b i) ==
FStar.Seq.Base.slice (FStar.Buffer.as_seq h b) (FStar.UInt32.v i) (FStar.Buffer.length b))
[
SMTPatOr [
[SMTPat (FStar.Buffer.as_seq h (FStar.Buffer.offset b i))];
[
SMTPat (FStar.Seq.Base.slice (FStar.Buffer.as_seq h b)
(FStar.UInt32.v i)
(FStar.Buffer.length b))
]
]
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"Prims.pow2",
"FStar.UInt32.n",
"Prims.op_LessThanOrEqual",
"FStar.Buffer.__proj__MkBuffer__item__length",
"FStar.Monotonic.HyperStack.mem",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"FStar.Buffer.offset",
"FStar.Seq.Base.slice",
"FStar.Buffer.length",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_offset_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h
: Lemma (requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[
SMTPatOr
[[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]
] =
| Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) | false |
FStar.Buffer.fst | FStar.Buffer.lemma_aux_2 | val lemma_aux_2 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem)
: Lemma (requires (live h0 b))
(ensures
(live h0 b /\
(forall (tt: Type) (bb: buffer tt).
(live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))) | val lemma_aux_2 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem)
: Lemma (requires (live h0 b))
(ensures
(live h0 b /\
(forall (tt: Type) (bb: buffer tt).
(live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))) | let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0)) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 998,
"start_col": 8,
"start_line": 990
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} ->
z: a ->
h0: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b)
(ensures
FStar.Buffer.live h0 b /\
(forall (tt: Type0) (bb: FStar.Buffer.buffer tt).
FStar.Buffer.live h0 bb /\ FStar.Buffer.disjoint b bb ==>
(let h1 =
FStar.Monotonic.HyperStack.upd h0
(MkBuffer?.content b)
(FStar.Seq.Base.upd (FStar.Buffer.sel h0 b)
(FStar.Buffer.idx b + FStar.UInt32.v n)
z)
in
FStar.Buffer.as_seq h0 bb == FStar.Buffer.as_seq h1 bb))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Monotonic.HyperStack.mem",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"FStar.Buffer.live",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Buffer.disjoint",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Buffer.as_seq",
"FStar.Monotonic.HyperStack.upd",
"FStar.Buffer.lseq",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"FStar.Heap.trivial_preorder",
"FStar.Buffer.__proj__MkBuffer__item__content",
"FStar.Seq.Base.upd",
"FStar.Buffer.sel",
"Prims.op_Addition",
"FStar.Buffer.idx",
"FStar.Classical.move_requires",
"FStar.Buffer.lemma_aux_1",
"Prims.unit",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_aux_2 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem)
: Lemma (requires (live h0 b))
(ensures
(live h0 b /\
(forall (tt: Type) (bb: buffer tt).
(live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))) =
| let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) | false |
FStar.Buffer.fst | FStar.Buffer.lemma_sub_spec | val lemma_sub_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t{v len <= length b /\ v i + v len <= length b})
(h: _)
: Lemma (requires (live h b))
(ensures
(live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)] | val lemma_sub_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t{v len <= length b /\ v i + v len <= length b})
(h: _)
: Lemma (requires (live h b))
(ensures
(live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)] | let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 92,
"end_line": 1056,
"start_col": 0,
"start_line": 1048
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
i: FStar.UInt32.t ->
len:
FStar.UInt32.t
{ FStar.UInt32.v len <= FStar.Buffer.length b /\
FStar.UInt32.v i + FStar.UInt32.v len <= FStar.Buffer.length b } ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma (requires FStar.Buffer.live h b)
(ensures
FStar.Buffer.live h (FStar.Buffer.sub b i len) /\
FStar.Buffer.as_seq h (FStar.Buffer.sub b i len) ==
FStar.Seq.Base.slice (FStar.Buffer.as_seq h b)
(FStar.UInt32.v i)
(FStar.UInt32.v i + FStar.UInt32.v len))
[SMTPat (FStar.Buffer.sub b i len); SMTPat (FStar.Buffer.live h b)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"Prims.op_Addition",
"FStar.Monotonic.HyperStack.mem",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"FStar.Buffer.sub",
"FStar.Seq.Base.slice",
"Prims.unit",
"FStar.Buffer.live",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"FStar.Buffer.includes",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_sub_spec
(#a: Type)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t{v len <= length b /\ v i + v len <= length b})
h
: Lemma (requires (live h b))
(ensures
(live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)] =
| Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) | false |
FStar.Buffer.fst | FStar.Buffer.eq_lemma1 | val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] | val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] | let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 1094,
"start_col": 0,
"start_line": 1093
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"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": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b1: FStar.Buffer.buffer a ->
b2: FStar.Buffer.buffer a ->
len:
FStar.UInt32.t
{ FStar.UInt32.v len <= FStar.Buffer.length b1 /\
FStar.UInt32.v len <= FStar.Buffer.length b2 } ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
forall (j: Prims.nat).
j < FStar.UInt32.v len ==> FStar.Buffer.get h b1 j == FStar.Buffer.get h b2 j)
(ensures FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len))
[SMTPat (FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Monotonic.HyperStack.mem",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"FStar.Buffer.sub",
"FStar.UInt32.__uint_to_t",
"Prims.unit"
] | [] | true | false | true | false | false | let eq_lemma1 #a b1 b2 len h =
| Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) | false |
FStar.Buffer.fst | FStar.Buffer.op_Array_Assignment | val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) | val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) | let op_Array_Assignment #a b n z = upd #a b n z | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 1147,
"start_col": 0,
"start_line": 1147
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 | b: FStar.Buffer.buffer a -> n: FStar.UInt32.t -> z: a -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"FStar.Buffer.upd",
"Prims.unit"
] | [] | false | true | false | false | false | let ( .()<- ) #a b n z =
| upd #a b n z | false |
FStar.Buffer.fst | FStar.Buffer.join | val join
(#t: _)
(b: buffer t)
(b':
buffer t
{ b.max_length == b'.max_length /\ b.content === b'.content /\
idx b + length b == idx b' })
: Tot (buffer t) | val join
(#t: _)
(b: buffer t)
(b':
buffer t
{ b.max_length == b'.max_length /\ b.content === b'.content /\
idx b + length b == idx b' })
: Tot (buffer t) | let join #t (b:buffer t) (b':buffer t{b.max_length == b'.max_length /\ b.content === b'.content /\ idx b + length b == idx b'}) : Tot (buffer t)
= MkBuffer (b.max_length) (b.content) (b.idx) (FStar.UInt32.(b.length +^ b'.length)) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 86,
"end_line": 1219,
"start_col": 0,
"start_line": 1218
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma
(requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2))
(ensures (modifies_one (frameOf b) h0 h2))
[SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)]
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(** Corresponds to memcpy *)
val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) ==
Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) ))
let rec blit #t a idx_a b idx_b len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
blit #t a idx_a b idx_b len';
let z = a.(idx_a +^ len') in
b.(idx_b +^ len') <- z;
let h1 = HST.get() in
Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len');
Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b));
Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b))
end
(** Corresponds to memset *)
val fill: #t:Type
-> b:buffer t
-> z:t
-> len:UInt32.t{v len <= length b}
-> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z
/\ Seq.slice (as_seq h1 b) (v len) (length b) ==
Seq.slice (as_seq h0 b) (v len) (length b) ))
let rec fill #t b z len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
fill #t b z len';
b.(len') <- z;
let h = HST.get() in
Seq.snoc_slice_index (as_seq h b) 0 (v len');
Seq.lemma_tail_slice (as_seq h b) (v len') (length b)
end;
let h1 = HST.get() in
Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z)
let split #t (b:buffer t) (i:UInt32.t{v i <= length b}) : Tot (buffer t * buffer t)
= sub b 0ul i, offset b i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer t ->
b':
FStar.Buffer.buffer t
{ MkBuffer?.max_length b == MkBuffer?.max_length b' /\
MkBuffer?.content b === MkBuffer?.content b' /\
FStar.Buffer.idx b + FStar.Buffer.length b == FStar.Buffer.idx b' }
-> FStar.Buffer.buffer t | Prims.Tot | [
"total"
] | [] | [
"FStar.Buffer.buffer",
"Prims.l_and",
"Prims.eq2",
"FStar.UInt32.t",
"FStar.Buffer.__proj__MkBuffer__item__max_length",
"Prims.op_Equals_Equals_Equals",
"FStar.HyperStack.ST.reference",
"FStar.Buffer.lseq",
"FStar.UInt32.v",
"FStar.Buffer.__proj__MkBuffer__item__content",
"Prims.int",
"Prims.op_Addition",
"FStar.Buffer.idx",
"FStar.Buffer.length",
"FStar.Buffer.MkBuffer",
"FStar.Buffer.__proj__MkBuffer__item__idx",
"FStar.UInt32.op_Plus_Hat",
"FStar.Buffer.__proj__MkBuffer__item__length"
] | [] | false | false | false | false | false | let join
#t
(b: buffer t)
(b':
buffer t
{ b.max_length == b'.max_length /\ b.content === b'.content /\
idx b + length b == idx b' })
: Tot (buffer t) =
| MkBuffer (b.max_length) (b.content) (b.idx) (let open FStar.UInt32 in b.length +^ b'.length) | false |
FStar.Buffer.fst | FStar.Buffer.eq_lemma2 | val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] | val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] | let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 66,
"end_line": 1112,
"start_col": 0,
"start_line": 1108
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 |
b1: FStar.Buffer.buffer a ->
b2: FStar.Buffer.buffer a ->
len:
FStar.UInt32.t
{ FStar.UInt32.v len <= FStar.Buffer.length b1 /\
FStar.UInt32.v len <= FStar.Buffer.length b2 } ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len))
(ensures
forall (j: Prims.nat).
j < FStar.UInt32.v len ==> FStar.Buffer.get h b1 j == FStar.Buffer.get h b2 j)
[SMTPat (FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Monotonic.HyperStack.mem",
"Prims.cut",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Buffer.get",
"FStar.Seq.Base.index",
"Prims.unit",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.length",
"FStar.Buffer.sub",
"FStar.UInt32.uint_to_t",
"FStar.Buffer.as_seq",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | true | false | false | let eq_lemma2 #a b1 b2 len h =
| let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j: nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j: nat). j < v len ==> get h b2 j == Seq.index s2 j) | false |
Pulse.JoinComp.fst | Pulse.JoinComp.join_comps | val join_comps
(g_then:env)
(e_then:st_term)
(c_then:comp_st)
(e_then_typing:st_typing g_then e_then c_then)
(g_else:env)
(e_else:st_term)
(c_else:comp_st)
(e_else_typing:st_typing g_else e_else c_else)
(post:post_hint_t)
: TacS (c:comp_st &
st_typing g_then e_then c &
st_typing g_else e_else c)
(requires
comp_post_matches_hint c_then (Some post) /\
comp_post_matches_hint c_else (Some post) /\
comp_pre c_then == comp_pre c_else)
(ensures fun (| c, _, _ |) ->
st_comp_of_comp c == st_comp_of_comp c_then /\
comp_post_matches_hint c (Some post)) | val join_comps
(g_then:env)
(e_then:st_term)
(c_then:comp_st)
(e_then_typing:st_typing g_then e_then c_then)
(g_else:env)
(e_else:st_term)
(c_else:comp_st)
(e_else_typing:st_typing g_else e_else c_else)
(post:post_hint_t)
: TacS (c:comp_st &
st_typing g_then e_then c &
st_typing g_else e_else c)
(requires
comp_post_matches_hint c_then (Some post) /\
comp_post_matches_hint c_else (Some post) /\
comp_pre c_then == comp_pre c_else)
(ensures fun (| c, _, _ |) ->
st_comp_of_comp c == st_comp_of_comp c_then /\
comp_post_matches_hint c (Some post)) | let join_comps
(g_then:env)
(e_then:st_term)
(c_then:comp_st)
(e_then_typing:st_typing g_then e_then c_then)
(g_else:env)
(e_else:st_term)
(c_else:comp_st)
(e_else_typing:st_typing g_else e_else c_else)
(post:post_hint_t)
: TacS (c:comp_st &
st_typing g_then e_then c &
st_typing g_else e_else c)
(requires
comp_post_matches_hint c_then (Some post) /\
comp_post_matches_hint c_else (Some post) /\
comp_pre c_then == comp_pre c_else)
(ensures fun (| c, _, _ |) ->
st_comp_of_comp c == st_comp_of_comp c_then /\
comp_post_matches_hint c (Some post))
= let g = g_then in
assert (st_comp_of_comp c_then == st_comp_of_comp c_else);
match c_then, c_else with
| C_STAtomic _ obs1 _, C_STAtomic _ obs2 _ ->
let obs = join_obs obs1 obs2 in
let e_then_typing = T_Lift _ _ _ _ e_then_typing (Lift_Observability g_then c_then obs) in
let e_else_typing = T_Lift _ _ _ _ e_else_typing (Lift_Observability g_else c_else obs) in
(| _, e_then_typing, e_else_typing |)
| _ ->
(| _, e_then_typing, e_else_typing |) | {
"file_name": "lib/steel/pulse/Pulse.JoinComp.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 41,
"end_line": 111,
"start_col": 0,
"start_line": 82
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.JoinComp
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Pure
open Pulse.Checker.Base
open Pulse.Checker.Prover
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Metatheory = Pulse.Typing.Metatheory
module RU = Pulse.RuntimeUtils
(* For now we just create a term with the union,
but this could potentially be smarter *)
let compute_iname_join (is1 is2 : term) : term =
tm_join_inames is1 is2
let lift_atomic_to_st
(g : env)
(e : st_term)
(c : comp_st{C_STAtomic? c})
(d : st_typing g e c)
: Pure (c':comp_st & st_typing g e c')
(requires True)
(ensures fun (| c', _ |) ->
st_comp_of_comp c' == st_comp_of_comp c /\
ctag_of_comp_st c' == STT)
= let C_STAtomic _ _ c_st = c in
let c' = C_ST c_st in
let d' : st_typing g e c' =
T_Lift g e c c' d (Lift_STAtomic_ST g c)
in
(| c', d' |)
let lift_ghost_to_atomic
(g : env)
(e : st_term)
(c : comp_st{C_STGhost? c})
(d : st_typing g e c)
: TacS (c':comp_st & st_typing g e c')
(requires True)
(ensures fun (| c', _ |) ->
st_comp_of_comp c' == st_comp_of_comp c /\
ctag_of_comp_st c' == STT_Atomic /\
tm_emp_inames == C_STAtomic?.inames c')
= let C_STGhost c_st = c in
let w : non_informative_c g c = get_non_informative_witness g (comp_u c) (comp_res c) in
FStar.Tactics.BreakVC.break_vc(); // somehow this proof is unstable, this helps
let c' = C_STAtomic tm_emp_inames Neutral c_st in
let d' : st_typing g e c' =
T_Lift g e c c' d (Lift_Ghost_Neutral g c w)
in
assert (st_comp_of_comp c' == st_comp_of_comp c);
assert (ctag_of_comp_st c' == STT_Atomic);
assert (tm_emp_inames == C_STAtomic?.inames c');
(| c', d' |)
(* This matches the effects of the two branches, without
necessarily matching inames. *)
#push-options "--z3rlimit 20"
open Pulse.Checker.Base
(* NB: g_then and g_else are equal except for containing one extra | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.BreakVC.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.JoinComp.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
g_then: Pulse.Typing.Env.env ->
e_then: Pulse.Syntax.Base.st_term ->
c_then: Pulse.Syntax.Base.comp_st ->
e_then_typing: Pulse.Typing.st_typing g_then e_then c_then ->
g_else: Pulse.Typing.Env.env ->
e_else: Pulse.Syntax.Base.st_term ->
c_else: Pulse.Syntax.Base.comp_st ->
e_else_typing: Pulse.Typing.st_typing g_else e_else c_else ->
post: Pulse.Typing.post_hint_t
-> Pulse.JoinComp.TacS
(FStar.Pervasives.dtuple3 Pulse.Syntax.Base.comp_st
(fun c -> Pulse.Typing.st_typing g_then e_then c)
(fun c _ -> Pulse.Typing.st_typing g_else e_else c)) | Pulse.JoinComp.TacS | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.st_typing",
"Pulse.Typing.post_hint_t",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.observability",
"Pulse.Syntax.Base.st_comp",
"FStar.Pervasives.Mkdtuple3",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.comp_inames",
"Pulse.Syntax.Base.st_comp_of_comp",
"Pulse.Typing.T_Lift",
"Pulse.Typing.Lift_Observability",
"Pulse.Typing.join_obs",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.dtuple3",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.l_and",
"Pulse.Typing.comp_post_matches_hint",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.comp_pre"
] | [] | false | true | false | false | false | let join_comps
(g_then: env)
(e_then: st_term)
(c_then: comp_st)
(e_then_typing: st_typing g_then e_then c_then)
(g_else: env)
(e_else: st_term)
(c_else: comp_st)
(e_else_typing: st_typing g_else e_else c_else)
(post: post_hint_t)
: TacS (c: comp_st & st_typing g_then e_then c & st_typing g_else e_else c)
(requires
comp_post_matches_hint c_then (Some post) /\ comp_post_matches_hint c_else (Some post) /\
comp_pre c_then == comp_pre c_else)
(ensures
fun (| c , _ , _ |) ->
st_comp_of_comp c == st_comp_of_comp c_then /\ comp_post_matches_hint c (Some post)) =
| let g = g_then in
assert (st_comp_of_comp c_then == st_comp_of_comp c_else);
match c_then, c_else with
| C_STAtomic _ obs1 _, C_STAtomic _ obs2 _ ->
let obs = join_obs obs1 obs2 in
let e_then_typing = T_Lift _ _ _ _ e_then_typing (Lift_Observability g_then c_then obs) in
let e_else_typing = T_Lift _ _ _ _ e_else_typing (Lift_Observability g_else c_else obs) in
(| _, e_then_typing, e_else_typing |)
| _ -> (| _, e_then_typing, e_else_typing |) | false |
FStar.Buffer.fst | FStar.Buffer.fill | val fill: #t:Type
-> b:buffer t
-> z:t
-> len:UInt32.t{v len <= length b}
-> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z
/\ Seq.slice (as_seq h1 b) (v len) (length b) ==
Seq.slice (as_seq h0 b) (v len) (length b) )) | val fill: #t:Type
-> b:buffer t
-> z:t
-> len:UInt32.t{v len <= length b}
-> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z
/\ Seq.slice (as_seq h1 b) (v len) (length b) ==
Seq.slice (as_seq h0 b) (v len) (length b) )) | let rec fill #t b z len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
fill #t b z len';
b.(len') <- z;
let h = HST.get() in
Seq.snoc_slice_index (as_seq h b) 0 (v len');
Seq.lemma_tail_slice (as_seq h b) (v len') (length b)
end;
let h1 = HST.get() in
Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 79,
"end_line": 1212,
"start_col": 0,
"start_line": 1199
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma
(requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2))
(ensures (modifies_one (frameOf b) h0 h2))
[SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)]
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(** Corresponds to memcpy *)
val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) ==
Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) ))
let rec blit #t a idx_a b idx_b len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
blit #t a idx_a b idx_b len';
let z = a.(idx_a +^ len') in
b.(idx_b +^ len') <- z;
let h1 = HST.get() in
Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len');
Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b));
Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b))
end
(** Corresponds to memset *)
val fill: #t:Type
-> b:buffer t
-> z:t
-> len:UInt32.t{v len <= length b}
-> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z
/\ Seq.slice (as_seq h1 b) (v len) (length b) == | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Buffer.buffer t -> z: t -> len: FStar.UInt32.t{FStar.UInt32.v len <= FStar.Buffer.length b}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Seq.Base.slice",
"FStar.Buffer.as_seq",
"FStar.Seq.Base.create",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.UInt32.op_Equals_Hat",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.Seq.Properties.lemma_tail_slice",
"FStar.Seq.Properties.snoc_slice_index",
"FStar.Buffer.op_Array_Assignment",
"FStar.Buffer.fill",
"FStar.UInt32.op_Subtraction_Hat"
] | [
"recursion"
] | false | true | false | false | false | let rec fill #t b z len =
| let h0 = HST.get () in
if len =^ 0ul
then ()
else
(let len' = len -^ 1ul in
fill #t b z len';
b.(len') <- z;
let h = HST.get () in
Seq.snoc_slice_index (as_seq h b) 0 (v len');
Seq.lemma_tail_slice (as_seq h b) (v len') (length b));
let h1 = HST.get () in
Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z) | false |
FStar.Buffer.fst | FStar.Buffer.eqb | val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len)))) | val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len)))) | let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 1128,
"start_col": 0,
"start_line": 1121
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 |
b1: FStar.Buffer.buffer a ->
b2: FStar.Buffer.buffer a ->
len:
FStar.UInt32.t
{ FStar.UInt32.v len <= FStar.Buffer.length b1 /\
FStar.UInt32.v len <= FStar.Buffer.length b2 }
-> FStar.HyperStack.ST.ST Prims.bool | FStar.HyperStack.ST.ST | [] | [] | [
"Prims.eqtype",
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.UInt32.op_Equals_Hat",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.Buffer.eqb",
"Prims.op_Equality",
"FStar.Buffer.index",
"FStar.UInt32.op_Subtraction_Hat"
] | [
"recursion"
] | false | true | false | false | false | let rec eqb #a b1 b2 len =
| if len =^ 0ul
then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then eqb b1 b2 len' else false | false |
FStar.Buffer.fst | FStar.Buffer.assignL | val assignL (#a: _) (l: list a) (b: buffer a)
: Stack unit
(requires (fun h0 -> live h0 b /\ length b = List.Tot.length l))
(ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l)) | val assignL (#a: _) (l: list a) (b: buffer a)
: Stack unit
(requires (fun h0 -> live h0 b /\ length b = List.Tot.length l))
(ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l)) | let rec assignL #a (l: list a) (b: buffer a): Stack unit
(requires (fun h0 ->
live h0 b /\
length b = List.Tot.length l))
(ensures (fun h0 _ h1 ->
live h1 b /\
modifies_1 b h0 h1 /\
as_seq h1 b == Seq.seq_of_list l))
= lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl ->
let b_hd = sub b 0ul 1ul in
let b_tl = offset b 1ul in
b_hd.(0ul) <- hd;
assignL tl b_tl;
let h = HST.get () in
assert (get h b_hd 0 == hd);
assert (as_seq h b_tl == Seq.seq_of_list tl);
assert (Seq.equal (as_seq h b) (Seq.append (as_seq h b_hd) (as_seq h b_tl)));
assert (Seq.equal (as_seq h b) (Seq.seq_of_list l)) | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 57,
"end_line": 1464,
"start_col": 0,
"start_line": 1444
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma
(requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2))
(ensures (modifies_one (frameOf b) h0 h2))
[SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)]
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(** Corresponds to memcpy *)
val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) ==
Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) ))
let rec blit #t a idx_a b idx_b len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
blit #t a idx_a b idx_b len';
let z = a.(idx_a +^ len') in
b.(idx_b +^ len') <- z;
let h1 = HST.get() in
Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len');
Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b));
Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b))
end
(** Corresponds to memset *)
val fill: #t:Type
-> b:buffer t
-> z:t
-> len:UInt32.t{v len <= length b}
-> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z
/\ Seq.slice (as_seq h1 b) (v len) (length b) ==
Seq.slice (as_seq h0 b) (v len) (length b) ))
let rec fill #t b z len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
fill #t b z len';
b.(len') <- z;
let h = HST.get() in
Seq.snoc_slice_index (as_seq h b) 0 (v len');
Seq.lemma_tail_slice (as_seq h b) (v len') (length b)
end;
let h1 = HST.get() in
Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z)
let split #t (b:buffer t) (i:UInt32.t{v i <= length b}) : Tot (buffer t * buffer t)
= sub b 0ul i, offset b i
let join #t (b:buffer t) (b':buffer t{b.max_length == b'.max_length /\ b.content === b'.content /\ idx b + length b == idx b'}) : Tot (buffer t)
= MkBuffer (b.max_length) (b.content) (b.idx) (FStar.UInt32.(b.length +^ b'.length))
val no_upd_lemma_0: #t:Type -> h0:mem -> h1:mem -> b:buffer t -> Lemma
(requires (live h0 b /\ modifies_0 h0 h1))
(ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b))
[SMTPat (modifies_0 h0 h1); SMTPat (live h0 b)]
let no_upd_lemma_0 #t h0 h1 b = ()
val no_upd_lemma_1: #t:Type -> #t':Type -> h0:mem -> h1:mem -> a:buffer t -> b:buffer t' -> Lemma
(requires (live h0 b /\ disjoint a b /\ modifies_1 a h0 h1))
(ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b))
[SMTPat (modifies_1 a h0 h1); SMTPat (live h0 b)]
let no_upd_lemma_1 #t #t' h0 h1 a b = ()
#reset-options "--z3rlimit 30 --initial_fuel 0 --max_fuel 0"
val no_upd_lemma_2: #t:Type -> #t':Type -> #t'':Type -> h0:mem -> h1:mem -> a:buffer t -> a':buffer t' -> b:buffer t'' -> Lemma
(requires (live h0 b /\ disjoint a b /\ disjoint a' b /\ modifies_2 a a' h0 h1))
(ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b))
[SMTPat (live h0 b); SMTPat (modifies_2 a a' h0 h1)]
let no_upd_lemma_2 #t #t' #t'' h0 h1 a a' b = ()
val no_upd_lemma_2_1: #t:Type -> #t':Type -> h0:mem -> h1:mem -> a:buffer t -> b:buffer t' -> Lemma
(requires (live h0 b /\ disjoint a b /\ modifies_2_1 a h0 h1))
(ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b))
[SMTPat (live h0 b); SMTPat (modifies_2_1 a h0 h1)]
let no_upd_lemma_2_1 #t #t' h0 h1 a b = ()
val no_upd_fresh: #t:Type -> h0:mem -> h1:mem -> a:buffer t -> Lemma
(requires (live h0 a /\ fresh_frame h0 h1))
(ensures (live h0 a /\ live h1 a /\ equal h0 a h1 a))
[SMTPat (live h0 a); SMTPat (fresh_frame h0 h1)]
let no_upd_fresh #t h0 h1 a = ()
val no_upd_popped: #t:Type -> h0:mem -> h1:mem -> b:buffer t -> Lemma
(requires (live h0 b /\ frameOf b =!= HS.get_tip h0 /\ popped h0 h1))
(ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b))
[SMTPat (live h0 b); SMTPat (popped h0 h1)]
let no_upd_popped #t h0 h1 b = ()
(* Modifies of subset lemmas *)
let lemma_modifies_sub_0 h0 h1 : Lemma
(requires (h1 == h0))
(ensures (modifies_0 h0 h1))
[SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_sub_1 #t h0 h1 (b:buffer t) : Lemma
(requires (h1 == h0))
(ensures (modifies_1 b h0 h1))
[SMTPat (live h0 b); SMTPat (modifies_1 b h0 h1)]
= ()
let lemma_modifies_sub_2 #t #t' h0 h1 (b:buffer t) (b':buffer t') : Lemma
(requires (h1 == h0))
(ensures (modifies_2 b b' h0 h1))
[SMTPat (live h0 b); SMTPat (live h0 b'); SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_sub_2_1 #t h0 h1 (b:buffer t) : Lemma
(requires (modifies_0 h0 h1 /\ live h0 b))
(ensures (modifies_2_1 b h0 h1))
[SMTPat (live h0 b); SMTPat (modifies_2_1 b h0 h1)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let modifies_subbuffer_1 (#t:Type) h0 h1 (sub:buffer t) (a:buffer t) : Lemma
(requires (live h0 a /\ modifies_1 sub h0 h1 /\ includes a sub))
(ensures (modifies_1 a h0 h1 /\ live h1 a))
[SMTPat (modifies_1 sub h0 h1); SMTPat (includes a sub)]
= ()
let modifies_subbuffer_2 (#t:Type) (#t':Type) h0 h1 (sub:buffer t) (a':buffer t') (a:buffer t) : Lemma
(requires (live h0 a /\ live h0 a' /\ includes a sub /\ modifies_2 sub a' h0 h1 ))
(ensures (modifies_2 a a' h0 h1 /\ modifies_2 a' a h0 h1 /\ live h1 a))
[SMTPat (modifies_2 sub a' h0 h1); SMTPat (includes a sub)]
= ()
let modifies_subbuffer_2' (#t:Type) (#t':Type) h0 h1 (sub:buffer t) (a':buffer t') (a:buffer t) : Lemma
(requires (live h0 a /\ live h0 a' /\ includes a sub /\ modifies_2 a' sub h0 h1 ))
(ensures (modifies_2 a a' h0 h1 /\ live h1 a))
[SMTPat (modifies_2 a' sub h0 h1); SMTPat (includes a sub)]
= ()
let modifies_subbuffer_2_1 (#t:Type) h0 h1 (sub:buffer t) (a:buffer t) : Lemma
(requires (live h0 a /\ includes a sub /\ modifies_2_1 sub h0 h1))
(ensures (modifies_2_1 a h0 h1 /\ live h1 a))
[SMTPat (modifies_2_1 sub h0 h1); SMTPat (includes a sub)]
= ()
let modifies_subbuffer_2_prime (#t:Type) h0 h1 (sub1:buffer t) (sub2:buffer t) (a:buffer t) : Lemma
(requires (live h0 a /\ includes a sub1 /\ includes a sub2 /\ modifies_2 sub1 sub2 h0 h1))
(ensures (modifies_1 a h0 h1 /\ live h1 a))
[SMTPat (modifies_2 sub1 sub2 h0 h1); SMTPat (includes a sub1); SMTPat (includes a sub2)]
= ()
let modifies_popped_3_2 (#t:Type) #t' (a:buffer t) (b:buffer t') h0 h1 h2 h3 : Lemma
(requires (live h0 a /\ live h0 b /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_3_2 a b h1 h2))
(ensures (modifies_2 a b h0 h3))
[SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_3_2 a b h1 h2)]
= ()
let modifies_popped_2 (#t:Type) #t' (a:buffer t) (b:buffer t') h0 h1 h2 h3 : Lemma
(requires (live h0 a /\ live h0 b /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_2 a b h1 h2))
(ensures (modifies_2 a b h0 h3))
[SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_2 a b h1 h2)]
= ()
let modifies_popped_1 (#t:Type) (a:buffer t) h0 h1 h2 h3 : Lemma
(requires (live h0 a /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_2_1 a h1 h2))
(ensures (modifies_1 a h0 h3))
[SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_2_1 a h1 h2)]
= ()
let modifies_popped_1' (#t:Type) (a:buffer t) h0 h1 h2 h3 : Lemma
(requires (live h0 a /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_1 a h1 h2))
(ensures (modifies_1 a h0 h3))
[SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_1 a h1 h2)]
= ()
let modifies_popped_0 h0 h1 h2 h3 : Lemma
(requires (fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h3))
[SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_0 h1 h2)]
= ()
let live_popped (#t:Type) (b:buffer t) h0 h1 : Lemma
(requires (popped h0 h1 /\ live h0 b /\ frameOf b =!= HS.get_tip h0))
(ensures (live h1 b))
[SMTPat (popped h0 h1); SMTPat (live h0 b)]
= ()
let live_fresh (#t:Type) (b:buffer t) h0 h1 : Lemma
(requires (fresh_frame h0 h1 /\ live h0 b))
(ensures (live h1 b))
[SMTPat (fresh_frame h0 h1); SMTPat (live h0 b)]
= ()
let modifies_0_to_2_1_lemma (#t:Type) h0 h1 (b:buffer t) : Lemma
(requires (modifies_0 h0 h1 /\ live h0 b))
(ensures (modifies_2_1 b h0 h1))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (live h0 b) ]
= ()
let lemma_modifies_none_push_pop h0 h1 h2 : Lemma
(requires (fresh_frame h0 h1 /\ popped h1 h2))
(ensures (modifies_none h0 h2))
= ()
let lemma_modifies_0_push_pop h0 h1 h2 h3 : Lemma
(requires (fresh_frame h0 h1 /\ modifies_0 h1 h2 /\ popped h2 h3))
(ensures (modifies_none h0 h3))
= ()
let modifies_1_to_2_1_lemma (#t:Type) h0 h1 (b:buffer t) : Lemma
(requires (modifies_1 b h0 h1 /\ live h0 b))
(ensures (modifies_2_1 b h0 h1))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (live h0 b) ]
= ()
(* let modifies_1_to_2_lemma (#t:Type) #t' h0 h1 (b:buffer t) (b':buffer t'): Lemma *)
(* (requires (modifies_1 b h0 h1 /\ live h0 b)) *)
(* (ensures (modifies_2 b b' h0 h1)) *)
(* [SMTPat (modifies_2 b b' h0 h1); SMTPat (live h0 b) ] *)
(* = () *)
let modifies_poppable_0 (h0 h1:mem) : Lemma
(requires (modifies_0 h0 h1 /\ HS.poppable h0))
(ensures (HS.poppable h1))
[SMTPat (modifies_0 h0 h1)]
= ()
let modifies_poppable_1 #t (h0 h1:mem) (b:buffer t) : Lemma
(requires (modifies_1 b h0 h1 /\ HS.poppable h0))
(ensures (HS.poppable h1))
[SMTPat (modifies_1 b h0 h1)]
= ()
let modifies_poppable_2_1 #t (h0 h1:mem) (b:buffer t) : Lemma
(requires (modifies_2_1 b h0 h1 /\ HS.poppable h0))
(ensures (HS.poppable h1))
[SMTPat (modifies_2_1 b h0 h1)]
= ()
let modifies_poppable_2 #t #t' (h0 h1:mem) (b:buffer t) (b':buffer t') : Lemma
(requires (modifies_2 b b' h0 h1 /\ HS.poppable h0))
(ensures (HS.poppable h1))
[SMTPat (modifies_2 b' b h0 h1)]
= ()
let modifies_poppable_3_2 #t #t' (h0 h1:mem) (b:buffer t) (b':buffer t') : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ HS.poppable h0))
(ensures (HS.poppable h1))
[SMTPat (modifies_3_2 b' b h0 h1)]
= ()
let lemma_fresh_poppable (h0 h1:mem) : Lemma
(requires (fresh_frame h0 h1))
(ensures (poppable h1))
[SMTPat (fresh_frame h0 h1)]
= ()
let lemma_equal_domains_popped (h0 h1 h2 h3:mem) : Lemma
(requires (equal_domains h0 h1 /\ popped h0 h2 /\ popped h1 h3))
(ensures (equal_domains h2 h3))
= ()
let lemma_equal_domains (h0 h1 h2 h3:mem) : Lemma
(requires (fresh_frame h0 h1 /\ equal_domains h1 h2 /\ popped h2 h3))
(ensures (equal_domains h0 h3))
[SMTPat (fresh_frame h0 h1); SMTPat (equal_domains h1 h2); SMTPat (popped h2 h3)]
= ()
let lemma_equal_domains_2 (h0 h1 h2 h3 h4:mem) : Lemma
(requires (fresh_frame h0 h1
/\ modifies_0 h1 h2 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h2)
/\ equal_domains h2 h3 /\ popped h3 h4))
(ensures (equal_domains h0 h4))
[SMTPat (fresh_frame h0 h1); SMTPat (modifies_0 h1 h2); SMTPat (popped h3 h4)]
= ()
#reset-options "--z3rlimit 50" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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 | l: Prims.list a -> b: FStar.Buffer.buffer a -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Prims.list",
"FStar.Buffer.buffer",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Buffer.as_seq",
"FStar.Seq.Base.seq_of_list",
"FStar.Seq.Base.append",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.length",
"FStar.Buffer.length",
"FStar.Buffer.get",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Buffer.assignL",
"FStar.Buffer.op_Array_Assignment",
"FStar.UInt32.__uint_to_t",
"FStar.Buffer.includes",
"FStar.Buffer.offset",
"Prims.l_and",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"FStar.Buffer.sub",
"FStar.Seq.Properties.lemma_seq_of_list_induction",
"FStar.Buffer.live",
"Prims.op_Equality",
"FStar.Buffer.modifies_1"
] | [
"recursion"
] | false | true | false | false | false | let rec assignL #a (l: list a) (b: buffer a)
: Stack unit
(requires (fun h0 -> live h0 b /\ length b = List.Tot.length l))
(ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l)) =
| lemma_seq_of_list_induction l;
match l with
| [] -> ()
| hd :: tl ->
let b_hd = sub b 0ul 1ul in
let b_tl = offset b 1ul in
b_hd.(0ul) <- hd;
assignL tl b_tl;
let h = HST.get () in
assert (get h b_hd 0 == hd);
assert (as_seq h b_tl == Seq.seq_of_list tl);
assert (Seq.equal (as_seq h b) (Seq.append (as_seq h b_hd) (as_seq h b_tl)));
assert (Seq.equal (as_seq h b) (Seq.seq_of_list l)) | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.lemma_proj_g_pow2_128_eval | val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128) | val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128) | let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 79,
"start_col": 0,
"start_line": 72
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
Spec.Exponentiation.exp_pow2 Spec.P256.mk_p256_concrete_ops
Hacl.P256.PrecompTable.proj_g_pow2_64
64 ==
Hacl.P256.PrecompTable.proj_g_pow2_128) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"Prims.nat",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Spec.P256.PointOps.felem",
"FStar.Pervasives.normalize_term_spec",
"Spec.P256.PointOps.proj_point",
"Hacl.Spec.PrecompBaseTable256.exp_pow2_rec",
"Spec.P256.mk_p256_concrete_ops",
"Hacl.P256.PrecompTable.proj_g_pow2_64",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.normalize_term",
"Hacl.Spec.PrecompBaseTable256.exp_pow2_rec_is_exp_pow2"
] | [] | false | false | true | false | false | let lemma_proj_g_pow2_128_eval () =
| SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX:S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY:S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ:S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) | false |
Benton2004.RHL.fst | Benton2004.RHL.exec_equiv | val exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0 | val exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0 | let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f' | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 54,
"start_col": 0,
"start_line": 50
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Benton2004.RHL.gexp Prims.bool ->
p': Benton2004.RHL.gexp Prims.bool ->
f: Benton2004.computation ->
f': Benton2004.computation
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.exec_equiv",
"Benton2004.RHL.interp"
] | [] | false | false | false | false | true | let exec_equiv (p p': gexp bool) (f f': computation) : GTot Type0 =
| Benton2004.exec_equiv (interp p) (interp p') f f' | false |
Benton2004.RHL.fst | Benton2004.RHL.holds_interp | val holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)] | val holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)] | let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2 | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 31,
"end_line": 48,
"start_col": 0,
"start_line": 42
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ge: Benton2004.RHL.gexp Prims.bool ->
s1: FStar.DM4F.Heap.IntStoreFixed.heap ->
s2: FStar.DM4F.Heap.IntStoreFixed.heap
-> FStar.Pervasives.Lemma
(ensures Benton2004.Aux.holds (Benton2004.RHL.interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (Benton2004.Aux.holds (Benton2004.RHL.interp ge) s1 s2)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Benton2004.Aux.holds_equiv",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Benton2004.Aux.holds",
"Prims.eq2",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let holds_interp (ge: gexp bool) (s1 s2: heap)
: Lemma (holds (interp ge) s1 s2 <==> ge s1 s2 == true) [SMTPat (holds (interp ge) s1 s2)] =
| holds_equiv (interp ge) s1 s2 | false |
Benton2004.RHL.fst | Benton2004.RHL.r_skip | val r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)] | val r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)] | let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p) | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 69,
"start_col": 0,
"start_line": 64
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma (ensures Benton2004.RHL.exec_equiv p p Benton2004.skip Benton2004.skip)
[SMTPat (Benton2004.RHL.exec_equiv p p Benton2004.skip Benton2004.skip)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.d_skip",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Benton2004.RHL.exec_equiv",
"Benton2004.skip",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_skip (p: gexp bool) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] =
| d_skip (interp p) | false |
Benton2004.RHL.fst | Benton2004.RHL.r_if | val r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
)) | val r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
)) | let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p' | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 212,
"start_col": 0,
"start_line": 186
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
b': Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
c': Benton2004.computation ->
d: Benton2004.computation ->
d': Benton2004.computation ->
p: Benton2004.RHL.gexp Prims.bool ->
p': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv (Benton2004.RHL.r_if_precond_true b b' c c' d d' p p') p' c c' /\
Benton2004.RHL.exec_equiv (Benton2004.RHL.r_if_precond_false b b' c c' d d' p p') p' d d')
(ensures
Benton2004.RHL.exec_equiv (Benton2004.RHL.r_if_precond b b' c c' d d' p p')
p'
(Benton2004.ifthenelse b c d)
(Benton2004.ifthenelse b' c' d')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Benton2004.RHL.holds_r_if_precond",
"Prims.unit",
"Benton2004.RHL.holds_r_if_precond_false",
"Benton2004.RHL.holds_r_if_precond_true",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Benton2004.RHL.r_if_precond_true",
"Benton2004.RHL.r_if_precond_false",
"Prims.squash",
"Benton2004.RHL.r_if_precond",
"Benton2004.ifthenelse",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let r_if (b b': exp bool) (c c' d d': computation) (p p': gexp bool)
: Lemma
(requires
(exec_equiv (r_if_precond_true b b' c c' d d' p p') p' c c' /\
exec_equiv (r_if_precond_false b b' c c' d d' p p') p' d d'))
(ensures
(exec_equiv (r_if_precond b b' c c' d d' p p') p' (ifthenelse b c d) (ifthenelse b' c' d'))) =
| holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p' | false |
Benton2004.RHL.fst | Benton2004.RHL.r_sub | val r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] | val r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] | let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f' | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 262,
"start_col": 0,
"start_line": 251
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: Benton2004.RHL.gexp Prims.bool ->
p2: Benton2004.RHL.gexp Prims.bool ->
p1': Benton2004.RHL.gexp Prims.bool ->
p2': Benton2004.RHL.gexp Prims.bool ->
f: Benton2004.computation ->
f': Benton2004.computation
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv p1 p2 f f' /\ Benton2004.RHL.included p1' p1 /\
Benton2004.RHL.included p2 p2')
(ensures Benton2004.RHL.exec_equiv p1' p2' f f')
[
SMTPat (Benton2004.RHL.exec_equiv p1' p2' f f');
SMTPat (Benton2004.RHL.exec_equiv p1 p2 f f')
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.d_csub",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Benton2004.RHL.included",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_sub (p1 p2 p1' p2': gexp bool) (f f': computation)
: Lemma (requires (exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2'))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] =
| d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f' | false |
Benton2004.RHL.fst | Benton2004.RHL.holds_interp_flip | val holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))] | val holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))] | let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi) | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 333,
"start_col": 0,
"start_line": 330
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | phi: Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(ensures
forall (s1: FStar.DM4F.Heap.IntStoreFixed.heap) (s2: FStar.DM4F.Heap.IntStoreFixed.heap).
Benton2004.Aux.holds (Benton2004.RHL.interp (Benton2004.RHL.flip phi)) s1 s2 <==>
Benton2004.Aux.holds (Benton2004.flip (Benton2004.RHL.interp phi)) s1 s2)
[SMTPat (Benton2004.Aux.holds (Benton2004.RHL.interp (Benton2004.RHL.flip phi)))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.holds_flip",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_iff",
"Benton2004.Aux.holds",
"Benton2004.RHL.flip",
"Benton2004.flip",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let holds_interp_flip (phi: gexp bool)
: Lemma
(forall s1 s2. holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2
) [SMTPat (holds (interp (flip phi)))] =
| Benton2004.holds_flip (interp phi) | false |
Benton2004.RHL.fst | Benton2004.RHL.included_alt | val included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)] | val included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)] | let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true) | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 249,
"start_col": 0,
"start_line": 245
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p1: Benton2004.RHL.gexp Prims.bool -> p2: Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(ensures
Benton2004.RHL.included p1 p2 <==>
(forall (s1: FStar.DM4F.Heap.IntStoreFixed.heap) (s2: FStar.DM4F.Heap.IntStoreFixed.heap).
p1 s1 s2 == true ==> p2 s1 s2 == true)) [SMTPat (Benton2004.RHL.included p1 p2)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Prims._assert",
"Prims.l_Forall",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Prims.l_iff",
"Benton2004.Aux.holds",
"Benton2004.RHL.interp",
"Prims.eq2",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Benton2004.RHL.included",
"Prims.l_imp",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let included_alt (p1 p2: gexp bool)
: Lemma (included p1 p2 <==> (forall s1 s2. p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)] =
| assert (forall s1 s2. holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2. holds (interp p2) s1 s2 <==> p2 s1 s2 == true) | false |
Steel.Channel.Simplex.fst | Steel.Channel.Simplex.send | val send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next)
: SteelT unit (sender c next) (fun _ -> sender c (step next x)) | val send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next)
: SteelT unit (sender c next) (fun _ -> sender c (step next x)) | let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next)
: SteelT unit (sender c next) (fun _ -> sender c (step next x))
= let v = send_receive_prelude c in //matching v as vs,vr fails
if (fst v).chan_ctr = (snd v).chan_ctr
then (
rewrite_slprop (chan_inv_cond (fst v) (snd v))
(pure (fst v == snd v))
(fun _ -> ());
send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails
)
else (
rewrite_slprop (chan_inv_cond (fst v) (snd v))
(chan_inv_step (snd v) (fst v))
(fun _ -> ());
intro_chan_inv_stepT c.chan_chan (fst v) (snd v);
Steel.SpinLock.release c.chan_lock;
send c x
) | {
"file_name": "lib/steel/Steel.Channel.Simplex.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 388,
"start_col": 0,
"start_line": 371
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Channel.Simplex
module P = Steel.Channel.Protocol
open Steel.SpinLock
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.HigherReference
open Steel.FractionalPermission
module MRef = Steel.MonotonicHigherReference
module H = Steel.HigherReference
let sprot = p:prot { more p }
noeq
type chan_val = {
chan_prot : sprot;
chan_msg : msg_t chan_prot;
chan_ctr : nat
}
let mref a p = MRef.ref a p
let trace_ref (p:prot) = mref (partial_trace_of p) extended_to
noeq
type chan_t (p:prot) = {
send: ref chan_val;
recv: ref chan_val;
trace: trace_ref p;
}
let half : perm = half_perm full_perm
let step (s:sprot) (x:msg_t s) = step s x
let chan_inv_step_p (vrecv vsend:chan_val) : prop =
(vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\
vsend.chan_ctr == vrecv.chan_ctr + 1)
let chan_inv_step (vrecv vsend:chan_val) : vprop =
pure (chan_inv_step_p vrecv vsend)
let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop =
if vsend.chan_ctr = vrecv.chan_ctr
then pure (vsend == vrecv)
else chan_inv_step vrecv vsend
let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop =
MRef.pts_to r full_perm tr `star`
pure (until tr == step vr.chan_prot vr.chan_msg)
let trace_until #p (r:trace_ref p) (vr:chan_val) =
h_exists (trace_until_prop r vr)
let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) =
h_exists (fun (vrecv:chan_val) ->
pts_to c.recv half vrecv `star`
trace_until c.trace vrecv `star`
chan_inv_cond vsend vrecv)
let chan_inv #p (c:chan_t p) : vprop =
h_exists (fun (vsend:chan_val) ->
pts_to c.send half vsend `star` chan_inv_recv c vsend)
let intro_chan_inv_cond_eqT (vs vr:chan_val)
: Steel unit emp
(fun _ -> chan_inv_cond vs vr)
(requires fun _ -> vs == vr)
(ensures fun _ _ _ -> True)
= intro_pure (vs == vs);
rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ())
let intro_chan_inv_cond_stepT (vs vr:chan_val)
: SteelT unit (chan_inv_step vr vs)
(fun _ -> chan_inv_cond vs vr)
= Steel.Utils.extract_pure (chan_inv_step_p vr vs);
rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ())
let intro_chan_inv_auxT #p (#vs : chan_val)
(#vr : chan_val)
(c:chan_t p)
: SteelT unit (pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr `star`
chan_inv_cond vs vr)
(fun _ -> chan_inv c)
= intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr);
intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs)
let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val)
: SteelT unit (pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr `star`
chan_inv_step vr vs)
(fun _ -> chan_inv c)
= intro_chan_inv_cond_stepT vs vr;
intro_chan_inv_auxT c
let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val)
: Steel unit (pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr)
(fun _ -> chan_inv c)
(requires fun _ -> vs == vr)
(ensures fun _ _ _ -> True)
= intro_chan_inv_cond_eqT vs vr;
intro_chan_inv_auxT c
noeq
type chan p = {
chan_chan : chan_t p;
chan_lock : lock (chan_inv chan_chan)
}
let in_state_prop (p:prot) (vsend:chan_val) : prop =
p == step vsend.chan_prot vsend.chan_msg
irreducible
let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 })
: Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs})
= {
chan_prot = (step vs0.chan_prot vs0.chan_msg);
chan_msg = x;
chan_ctr = vs0.chan_ctr + 1
}
[@@__reduce__]
let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend)
let in_state (r:ref chan_val) (p:prot) =
h_exists (fun (vsend:chan_val) ->
pts_to r half vsend `star` in_state_slprop p vsend)
let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p
let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p
let intro_chan_inv #p (c:chan_t p) (v:chan_val)
: SteelT unit (pts_to c.send half v `star`
pts_to c.recv half v `star`
trace_until c.trace v)
(fun _ -> chan_inv c)
= intro_chan_inv_eqT c v v
let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 })
let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p)
: SteelT unit (pts_to r half v) (fun _ -> in_state r p)
= intro_pure (in_state_prop p v);
intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v)
let msg t p = Msg Send unit (fun _ -> p)
let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p}
let initial_trace (p:prot) : (q:partial_trace_of p {until q == p})
= { to = p; tr=Waiting p}
let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val)
: Steel unit (MRef.pts_to r full_perm tr)
(fun _ -> trace_until r v)
(requires fun _ -> until tr == step v.chan_prot v.chan_msg)
(ensures fun _ _ _ -> True)
= intro_pure (until tr == step v.chan_prot v.chan_msg);
intro_exists tr
(fun (tr:partial_trace_of q) ->
MRef.pts_to r full_perm tr `star`
pure (until tr == (step v.chan_prot v.chan_msg)));
()
let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv})
let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p)
: SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p))
(fun _ -> trace_until c.trace v)
= intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg);
//TODO: Not sure why I need this rewrite
rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star`
pure (until (initial_trace p) == step v.chan_prot v.chan_msg))
(MRef.pts_to c.trace full_perm (initial_trace p) `star`
pure (until (initial_trace p) == step v.chan_prot v.chan_msg))
(fun _ -> ());
intro_exists (initial_trace p) (trace_until_prop c.trace v)
let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p)
: SteelT (chan_t_sr p send recv)
(pts_to send half v `star` pts_to recv half v)
(fun c -> chan_inv c)
= let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in
let c = Mkchan_t send recv tr in
rewrite_slprop
(MRef.pts_to tr full_perm (initial_trace p))
(MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ());
intro_trace_until_init c v;
rewrite_slprop
(pts_to send half v `star` pts_to recv half v)
(pts_to c.send half v `star` pts_to c.recv half v)
(fun _ -> ());
intro_chan_inv #p c v;
let c' : chan_t_sr p send recv = c in
rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ());
return c'
let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p)
= let q = msg unit p in
let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in
let vp : init_chan_val p = v in
let send = H.alloc v in
let recv = H.alloc v in
H.share recv;
H.share send;
(* TODO: use smt_fallback *)
rewrite_slprop (pts_to send (half_perm full_perm) v `star`
pts_to send (half_perm full_perm) v `star`
pts_to recv (half_perm full_perm) v `star`
pts_to recv (half_perm full_perm) v)
(pts_to send half vp `star`
pts_to send half vp `star`
pts_to recv half vp `star`
pts_to recv half vp)
(fun _ -> ());
let c = mk_chan send recv vp in
intro_in_state send p vp;
intro_in_state recv p vp;
let l = Steel.SpinLock.new_lock (chan_inv c) in
let ch = { chan_chan = c; chan_lock = l } in
rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ());
rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ());
return ch
[@@__reduce__]
let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop =
(pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr `star`
pure (vs == vr) `star`
in_state r p)
[@@__reduce__]
let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop =
(pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr `star`
chan_inv_step vr vs `star`
in_state r p)
let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val)
: SteelT chan_val
(pts_to r full_perm vs `star` in_state_slprop p vs)
(fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs'))
= elim_pure (in_state_prop p vs);
let vs' = next_chan_val x vs in
H.write r vs';
intro_pure (in_state_prop (step p x) vs');
intro_pure (chan_inv_step_p vs vs');
return vs'
[@@__reduce__]
let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr
let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val)
: SteelT unit
(pts_to r half v `star` in_state r p)
(fun _ -> pts_to r full_perm v `star` in_state_slprop p v)
= let v' = witness_exists () in
H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r;
H.gather #_ #_ #half #half #v #v r;
rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ());
rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ())
let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit)
: SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x))
= Steel.Utils.extract_pure (vs == vr);
Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs;
elim_pure (vs == vs);
gather_r cc.chan_chan.send vs;
let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in
H.share cc.chan_chan.send;
intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs);
intro_chan_inv_stepT cc.chan_chan next_vs vs;
Steel.SpinLock.release cc.chan_lock
let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to
let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to
let next_trace #p (vr:chan_val) (vs:chan_val)
(tr:partial_trace_of p)
(s:squash (until tr == step vr.chan_prot vr.chan_msg))
(_:squash (chan_inv_step_p vr vs))
: (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg })
= let msg : next_msg_t tr = vs.chan_msg in
assert (extensible tr);
extend_partial_trace tr msg
let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p)
: Steel (extension_of tr)
(chan_inv_step vr vs)
(fun _ -> emp)
(requires fun _ -> until tr == step vr.chan_prot vr.chan_msg)
(ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg)
= elim_pure (chan_inv_step_p vr vs);
let ts : extension_of tr = next_trace vr vs tr () () in
return ts
let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val)
: Steel unit
(trace_until r vr)
(fun _ -> trace_until r vs)
(requires fun _ -> chan_inv_step_p vr vs)
(ensures fun _ _ _ -> True)
= intro_pure (chan_inv_step_p vr vs);
let tr = MRef.read_refine r in
elim_pure (until tr == step vr.chan_prot vr.chan_msg);
let ts : extension_of tr = next_trace_st vr vs tr in
MRef.write r ts;
intro_pure (until ts == step vs.chan_prot vs.chan_msg);
intro_exists ts
(fun (ts:partial_trace_of p) ->
MRef.pts_to r full_perm ts `star`
pure (until ts == step vs.chan_prot vs.chan_msg))
let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit)
: SteelT (msg_t p)
(sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr)
(fun x -> receiver cc (step p x))
= elim_pure (chan_inv_step_p vr vs);
gather_r cc.chan_chan.recv vr;
elim_pure (in_state_prop p vr);
H.write cc.chan_chan.recv vs;
H.share cc.chan_chan.recv;
assert (vs.chan_prot == p);
let vs_msg : msg_t p = vs.chan_msg in
intro_pure (in_state_prop (step p vs_msg) vs);
intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs);
update_trace cc.chan_chan.trace vr vs;
intro_chan_inv cc.chan_chan vs;
Steel.SpinLock.release cc.chan_lock;
vs_msg
#push-options "--ide_id_info_off"
let send_receive_prelude (#p:prot) (cc:chan p)
: SteelT (chan_val & chan_val)
emp
(fun v ->
pts_to cc.chan_chan.send half (fst v) `star`
pts_to cc.chan_chan.recv half (snd v) `star`
trace_until cc.chan_chan.trace (snd v) `star`
chan_inv_cond (fst v) (snd v))
= let c = cc.chan_chan in
Steel.SpinLock.acquire cc.chan_lock;
let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in
let _ = witness_exists () in
let vr = H.read cc.chan_chan.recv in
rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _)
(trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr)
(fun _ -> ());
return (vs, vr) | {
"checked_file": "/",
"dependencies": [
"Steel.Utils.fst.checked",
"Steel.SpinLock.fsti.checked",
"Steel.MonotonicHigherReference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Steel.Channel.Protocol.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Channel.Simplex.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.MonotonicHigherReference",
"short_module": "MRef"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.HigherReference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.SpinLock",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Channel.Protocol",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel.Protocol",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Steel.Channel.Simplex.chan p -> x: Steel.Channel.Protocol.msg_t next
-> Steel.Effect.SteelT Prims.unit | Steel.Effect.SteelT | [] | [] | [
"Steel.Channel.Simplex.prot",
"Steel.Channel.Simplex.chan",
"Prims.b2t",
"Steel.Channel.Protocol.more",
"Steel.Channel.Protocol.msg_t",
"Prims.op_Equality",
"Prims.nat",
"Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_ctr",
"FStar.Pervasives.Native.fst",
"Steel.Channel.Simplex.chan_val",
"FStar.Pervasives.Native.snd",
"Steel.Channel.Simplex.send_available",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Channel.Simplex.chan_inv_cond",
"Steel.Effect.Common.pure",
"Prims.eq2",
"Steel.Memory.mem",
"Prims.bool",
"Steel.Channel.Simplex.send",
"Steel.SpinLock.release",
"Steel.Channel.Simplex.chan_inv",
"Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan",
"Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock",
"Steel.Channel.Simplex.intro_chan_inv_stepT",
"Steel.Channel.Simplex.chan_inv_step",
"FStar.Pervasives.Native.tuple2",
"Steel.Channel.Simplex.send_receive_prelude",
"Steel.Channel.Simplex.sender",
"Steel.Channel.Simplex.step",
"Steel.Effect.Common.vprop"
] | [
"recursion"
] | false | true | false | false | false | let rec send (#p: prot) (c: chan p) (#next: prot{more next}) (x: msg_t next)
: SteelT unit (sender c next) (fun _ -> sender c (step next x)) =
| let v = send_receive_prelude c in
if (fst v).chan_ctr = (snd v).chan_ctr
then
(rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ());
send_available c x (fst v) (snd v) ())
else
(rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ());
intro_chan_inv_stepT c.chan_chan (fst v) (snd v);
Steel.SpinLock.release c.chan_lock;
send c x) | false |
Benton2004.RHL.fst | Benton2004.RHL.exec_equiv_flip | val exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')] | val exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')] | let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f' | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 343,
"start_col": 0,
"start_line": 335
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Benton2004.RHL.gexp Prims.bool ->
p': Benton2004.RHL.gexp Prims.bool ->
f: Benton2004.computation ->
f': Benton2004.computation
-> FStar.Pervasives.Lemma
(ensures
Benton2004.RHL.exec_equiv (Benton2004.RHL.flip p) (Benton2004.RHL.flip p') f f' <==>
Benton2004.RHL.exec_equiv p p' f' f)
[SMTPat (Benton2004.RHL.exec_equiv (Benton2004.RHL.flip p) (Benton2004.RHL.flip p') f f')] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.exec_equiv_flip",
"Benton2004.RHL.interp",
"Prims.unit",
"Benton2004.RHL.holds_interp_flip",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Benton2004.RHL.exec_equiv",
"Benton2004.RHL.flip",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let exec_equiv_flip (p p': gexp bool) (f f': computation)
: Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')] =
| holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f' | false |
Benton2004.RHL.fst | Benton2004.RHL.r_seq | val r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]] | val r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]] | let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12' | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 230,
"start_col": 0,
"start_line": 214
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p0: Benton2004.RHL.gexp Prims.bool ->
p1: Benton2004.RHL.gexp Prims.bool ->
p2: Benton2004.RHL.gexp Prims.bool ->
c01: Benton2004.computation ->
c01': Benton2004.computation ->
c12: Benton2004.computation ->
c12': Benton2004.computation
-> FStar.Pervasives.Lemma
(requires Benton2004.RHL.exec_equiv p0 p1 c01 c01' /\ Benton2004.RHL.exec_equiv p1 p2 c12 c12'
)
(ensures Benton2004.RHL.exec_equiv p0 p2 (Benton2004.seq c01 c12) (Benton2004.seq c01' c12'))
[
SMTPatOr [
[
SMTPat (Benton2004.RHL.exec_equiv p0
p2
(Benton2004.seq c01 c12)
(Benton2004.seq c01' c12'));
SMTPat (Benton2004.RHL.exec_equiv p0 p1 c01 c01')
];
[
SMTPat (Benton2004.RHL.exec_equiv p0
p2
(Benton2004.seq c01 c12)
(Benton2004.seq c01' c12'));
SMTPat (Benton2004.RHL.exec_equiv p1 p2 c12 c12')
];
[
SMTPat (Benton2004.RHL.exec_equiv p0 p1 c01 c01');
SMTPat (Benton2004.RHL.exec_equiv p1 p2 c12 c12')
]
]
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.d_seq",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Prims.squash",
"Benton2004.seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_seq (p0 p1 p2: gexp bool) (c01 c01' c12 c12': computation)
: Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12'))
(ensures (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')))
[
SMTPatOr
[
[
SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'));
SMTPat (exec_equiv p0 p1 c01 c01')
];
[
SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'));
SMTPat (exec_equiv p1 p2 c12 c12')
];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]
]
] =
| d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12' | false |
Benton2004.RHL.fst | Benton2004.RHL.r_while_terminates | val r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
)) | val r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
)) | let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0)) | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 127,
"end_line": 363,
"start_col": 0,
"start_line": 345
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
b': Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
c': Benton2004.computation ->
p: Benton2004.RHL.gexp Prims.bool ->
s0: FStar.DM4F.Heap.IntStoreFixed.heap ->
s0': FStar.DM4F.Heap.IntStoreFixed.heap
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv (Benton2004.RHL.gand p
(Benton2004.RHL.gand (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
(Benton2004.RHL.gand p
(Benton2004.RHL.geq (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
c
c' /\
Benton2004.Aux.holds (Benton2004.RHL.interp (Benton2004.RHL.gand p
(Benton2004.RHL.geq (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right))))
s0
s0')
(ensures
Benton2004.terminates_on (Benton2004.reify_computation (Benton2004.while b c)) s0 <==>
Benton2004.terminates_on (Benton2004.reify_computation (Benton2004.while b' c')) s0') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"FStar.Classical.forall_intro",
"Prims.nat",
"Prims.l_imp",
"Prims.l_and",
"Benton2004.RHL.included",
"Benton2004.RHL.flip",
"Benton2004.RHL.geq",
"Benton2004.RHL.exp_to_gexp",
"Benton2004.RHL.Left",
"Benton2004.RHL.Right",
"Benton2004.RHL.gand",
"Benton2004.RHL.exec_equiv",
"Benton2004.Aux.holds",
"Benton2004.RHL.interp",
"Prims.eq2",
"FStar.Pervasives.Native.fst",
"Benton2004.reify_computation",
"Benton2004.while",
"Benton2004.terminates_on",
"FStar.Classical.move_requires",
"Benton2004.RHL.r_while_terminates'",
"Prims.unit",
"Prims.squash",
"Prims.l_iff",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let r_while_terminates (b b': exp bool) (c c': computation) (p: gexp bool) (s0 s0': heap)
: Lemma
(requires
(exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))
(gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))
c
c' /\ holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'))
(ensures
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0')) =
| let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b
b'
c
c'
phi
phi_c
phi_c'
s0
s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b'
b
c'
c
(flip phi)
(flip phi_c)
(flip phi_c')
s0'
s0)) | false |
Benton2004.RHL.fst | Benton2004.RHL.is_per_gand | val is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2))) | val is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2))) | let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2) | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 153,
"end_line": 442,
"start_col": 0,
"start_line": 437
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e1: Benton2004.RHL.gexp Prims.bool -> e2: Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma (requires Benton2004.RHL.is_per e1 /\ Benton2004.RHL.is_per e2)
(ensures Benton2004.RHL.is_per (Benton2004.RHL.gand e1 e2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Prims._assert",
"Prims.l_Forall",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Prims.l_iff",
"Benton2004.Aux.holds",
"Benton2004.RHL.interp",
"Benton2004.RHL.gand",
"Prims.l_and",
"Prims.unit",
"Benton2004.RHL.is_per",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let is_per_gand (e1 e2: gexp bool)
: Lemma (requires (is_per e1 /\ is_per e2)) (ensures (is_per (gand e1 e2))) =
| assert (forall s1 s2. {:pattern (interp (gand e1 e2) s1 s2)}
holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2) | false |
Benton2004.RHL.fst | Benton2004.RHL.r_sym | val r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')] | val r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')] | let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f' | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 460,
"start_col": 0,
"start_line": 453
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Benton2004.RHL.gexp Prims.bool ->
p': Benton2004.RHL.gexp Prims.bool ->
f: Benton2004.computation ->
f': Benton2004.computation
-> FStar.Pervasives.Lemma (requires Benton2004.RHL.is_per p /\ Benton2004.RHL.is_per p')
(ensures Benton2004.RHL.exec_equiv p p' f f' <==> Benton2004.RHL.exec_equiv p p' f' f)
[
SMTPat (Benton2004.RHL.exec_equiv p p' f f');
SMTPat (Benton2004.RHL.is_per p);
SMTPat (Benton2004.RHL.is_per p')
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.exec_equiv_sym",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_and",
"Benton2004.RHL.is_per",
"Prims.squash",
"Prims.l_iff",
"Benton2004.RHL.exec_equiv",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_sym (p p': gexp bool) (f f': computation)
: Lemma (requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')] =
| exec_equiv_sym (interp p) (interp p') f f' | false |
Benton2004.RHL.fst | Benton2004.RHL.r_while | val r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
)) | val r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
)) | let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 420,
"start_col": 0,
"start_line": 393
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
b': Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
c': Benton2004.computation ->
p: Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv (Benton2004.RHL.gand p
(Benton2004.RHL.gand (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
(Benton2004.RHL.gand p
(Benton2004.RHL.geq (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
c
c')
(ensures
Benton2004.RHL.exec_equiv (Benton2004.RHL.gand p
(Benton2004.RHL.geq (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
(Benton2004.RHL.gand p
(Benton2004.RHL.gnot (Benton2004.RHL.gor (Benton2004.RHL.exp_to_gexp b
Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right))))
(Benton2004.while b c)
(Benton2004.while b' c')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"FStar.Classical.forall_intro_3",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Prims.nat",
"Prims.l_imp",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Benton2004.RHL.gand",
"Benton2004.RHL.exp_to_gexp",
"Benton2004.RHL.Left",
"Benton2004.RHL.Right",
"Benton2004.RHL.geq",
"Benton2004.Aux.holds",
"Benton2004.RHL.interp",
"Prims.eq2",
"FStar.Pervasives.Native.fst",
"Benton2004.reify_computation",
"Benton2004.while",
"Benton2004.RHL.gnot",
"Benton2004.RHL.gor",
"FStar.Pervasives.Native.snd",
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Prims.l_iff",
"Benton2004.terminates_on",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.move_requires",
"Benton2004.RHL.r_while_correct",
"Benton2004.RHL.r_while_terminates"
] | [
"recursion"
] | false | false | true | false | false | let rec r_while (b b': exp bool) (c c': computation) (p: gexp bool)
: Lemma
(requires
(exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))
(gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))
c
c'))
(ensures
(exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))
(gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))
(while b c)
(while b' c'))) =
| let g (s0 s0': heap)
: Lemma
((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))
(gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))
c
c' /\ holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0')) =
Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0': heap) (fuel: nat)
: Lemma
((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))
(gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))
c
c' /\ holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))))
(snd (reify_computation (while b c) fuel s0))
(snd (reify_computation (while b' c') fuel s0')))) =
Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h | false |
Benton2004.RHL.fst | Benton2004.RHL.r_while_correct | val r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel) | val r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel) | let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else () | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 391,
"start_col": 0,
"start_line": 365
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
b': Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
c': Benton2004.computation ->
p: Benton2004.RHL.gexp Prims.bool ->
s0: FStar.DM4F.Heap.IntStoreFixed.heap ->
s0': FStar.DM4F.Heap.IntStoreFixed.heap ->
fuel: Prims.nat
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv (Benton2004.RHL.gand p
(Benton2004.RHL.gand (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
(Benton2004.RHL.gand p
(Benton2004.RHL.geq (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
c
c' /\
Benton2004.Aux.holds (Benton2004.RHL.interp (Benton2004.RHL.gand p
(Benton2004.RHL.geq (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right))))
s0
s0' /\
FStar.Pervasives.Native.fst (Benton2004.reify_computation (Benton2004.while b c) fuel s0) ==
true /\
FStar.Pervasives.Native.fst (Benton2004.reify_computation (Benton2004.while b' c') fuel s0') ==
true)
(ensures
Benton2004.Aux.holds (Benton2004.RHL.interp (Benton2004.RHL.gand p
(Benton2004.RHL.gnot (Benton2004.RHL.gor (Benton2004.RHL.exp_to_gexp b
Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))))
(FStar.Pervasives.Native.snd (Benton2004.reify_computation (Benton2004.while b c) fuel s0)
)
(FStar.Pervasives.Native.snd (Benton2004.reify_computation (Benton2004.while b' c')
fuel
s0')))
(decreases fuel) | FStar.Pervasives.Lemma | [
"",
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Prims.nat",
"FStar.Pervasives.Native.fst",
"Benton2004.reify_exp",
"Benton2004.RHL.r_while_correct",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.snd",
"Prims.unit",
"Benton2004.reified_computation",
"Benton2004.reify_computation",
"Benton2004.while",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Benton2004.RHL.gand",
"Benton2004.RHL.exp_to_gexp",
"Benton2004.RHL.Left",
"Benton2004.RHL.Right",
"Benton2004.RHL.geq",
"Benton2004.Aux.holds",
"Benton2004.RHL.interp",
"Prims.eq2",
"Prims.squash",
"Benton2004.RHL.gnot",
"Benton2004.RHL.gor",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec r_while_correct
(b b': exp bool)
(c c': computation)
(p: gexp bool)
(s0 s0': heap)
(fuel: nat)
: Lemma
(requires
(exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))
(gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))
c
c' /\ holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true))
(ensures
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))))
(snd (reify_computation (while b c) fuel s0))
(snd (reify_computation (while b' c') fuel s0'))))
(decreases fuel) =
| let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1) | false |
Benton2004.RHL.fst | Benton2004.RHL.d_su1 | val d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)] | val d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)] | let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi') | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 520,
"start_col": 0,
"start_line": 513
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c: Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma (requires Benton2004.RHL.exec_equiv phi phi' c c)
(ensures Benton2004.RHL.exec_equiv phi phi' (Benton2004.seq Benton2004.skip c) c)
[SMTPat (Benton2004.RHL.exec_equiv phi phi' (Benton2004.seq Benton2004.skip c) c)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.d_su1",
"Benton2004.RHL.interp",
"Prims.unit",
"Benton2004.RHL.exec_equiv",
"Prims.squash",
"Benton2004.seq",
"Benton2004.skip",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let d_su1 (c: computation) (phi phi': gexp bool)
: Lemma (requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)] =
| Benton2004.d_su1 c (interp phi) (interp phi') | false |
Benton2004.RHL.fst | Benton2004.RHL.d_su2 | val d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)] | val d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)] | let d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)]
= Benton2004.d_su2 c (interp phi) (interp phi') | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 545,
"start_col": 0,
"start_line": 538
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *)
let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi')
let d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]]
= Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c: Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma (requires Benton2004.RHL.exec_equiv phi phi' c c)
(ensures Benton2004.RHL.exec_equiv phi phi' (Benton2004.seq c Benton2004.skip) c)
[SMTPat (Benton2004.RHL.exec_equiv phi phi' (Benton2004.seq c Benton2004.skip) c)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.d_su2",
"Benton2004.RHL.interp",
"Prims.unit",
"Benton2004.RHL.exec_equiv",
"Prims.squash",
"Benton2004.seq",
"Benton2004.skip",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let d_su2 (c: computation) (phi phi': gexp bool)
: Lemma (requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)] =
| Benton2004.d_su2 c (interp phi) (interp phi') | false |
Benton2004.RHL.fst | Benton2004.RHL.r_trans | val r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]] | val r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]] | let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3 | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 509,
"start_col": 0,
"start_line": 493
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Benton2004.RHL.gexp Prims.bool ->
p': Benton2004.RHL.gexp Prims.bool ->
c1: Benton2004.computation ->
c2: Benton2004.computation ->
c3: Benton2004.computation
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.is_per p' /\ Benton2004.RHL.interpolable p /\
Benton2004.RHL.exec_equiv p p' c1 c2 /\ Benton2004.RHL.exec_equiv p p' c2 c3)
(ensures Benton2004.RHL.exec_equiv p p' c1 c3)
[
SMTPatOr [
[
SMTPat (Benton2004.RHL.exec_equiv p p' c1 c2);
SMTPat (Benton2004.RHL.exec_equiv p p' c2 c3);
SMTPat (Benton2004.RHL.is_per p');
SMTPat (Benton2004.RHL.interpolable p)
];
[
SMTPat (Benton2004.RHL.exec_equiv p p' c1 c2);
SMTPat (Benton2004.RHL.exec_equiv p p' c1 c3);
SMTPat (Benton2004.RHL.is_per p');
SMTPat (Benton2004.RHL.interpolable p)
];
[
SMTPat (Benton2004.RHL.exec_equiv p p' c1 c3);
SMTPat (Benton2004.RHL.exec_equiv p p' c2 c3);
SMTPat (Benton2004.RHL.is_per p');
SMTPat (Benton2004.RHL.interpolable p)
]
]
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.exec_equiv_trans",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_and",
"Benton2004.RHL.is_per",
"Benton2004.RHL.interpolable",
"Benton2004.RHL.exec_equiv",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_trans (p p': gexp bool) (c1 c2 c3: computation)
: Lemma
(requires (is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3))
(ensures (exec_equiv p p' c1 c3))
[
SMTPatOr
[
[
SMTPat (exec_equiv p p' c1 c2);
SMTPat (exec_equiv p p' c2 c3);
SMTPat (is_per p');
SMTPat (interpolable p)
];
[
SMTPat (exec_equiv p p' c1 c2);
SMTPat (exec_equiv p p' c1 c3);
SMTPat (is_per p');
SMTPat (interpolable p)
];
[
SMTPat (exec_equiv p p' c1 c3);
SMTPat (exec_equiv p p' c2 c3);
SMTPat (is_per p');
SMTPat (interpolable p)
]
]
] =
| exec_equiv_trans (interp p) (interp p') c1 c2 c3 | false |
Benton2004.RHL.fst | Benton2004.RHL.d_su1' | val d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]] | val d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]] | let d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]]
= Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'') | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 536,
"start_col": 0,
"start_line": 522
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *)
let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c: Benton2004.computation ->
c': Benton2004.computation ->
c'': Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool ->
phi'': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv phi phi' c Benton2004.skip /\
Benton2004.RHL.exec_equiv phi' phi'' c' c'')
(ensures Benton2004.RHL.exec_equiv phi phi'' (Benton2004.seq c c') c'')
[
SMTPatOr [
[
SMTPat (Benton2004.RHL.exec_equiv phi phi'' (Benton2004.seq c c') c'');
SMTPat (Benton2004.RHL.exec_equiv phi phi' c Benton2004.skip)
];
[
SMTPat (Benton2004.RHL.exec_equiv phi phi'' (Benton2004.seq c c') c'');
SMTPat (Benton2004.RHL.exec_equiv phi' phi'' c' c'')
];
[
SMTPat (Benton2004.RHL.exec_equiv phi' phi'' c' c'');
SMTPat (Benton2004.RHL.exec_equiv phi phi' c Benton2004.skip)
]
]
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.d_su1'",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Benton2004.skip",
"Prims.squash",
"Benton2004.seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let d_su1' (c c' c'': computation) (phi phi' phi'': gexp bool)
: Lemma (requires (exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c''))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[
SMTPatOr
[
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)]
]
] =
| Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'') | false |
Benton2004.RHL.fst | Benton2004.RHL.d_lu1 | val d_lu1
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) | val d_lu1
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) | let d_lu1
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip)))
= Benton2004.d_lu1 b c (interp phi) (interp phi') | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 582,
"start_col": 0,
"start_line": 575
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *)
let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi')
let d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]]
= Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'')
let d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)]
= Benton2004.d_su2 c (interp phi) (interp phi')
let d_assoc
(c1 c2 c3: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))]
= Benton2004.d_assoc c1 c2 c3 (interp phi) (interp phi')
let d_cc
(b: exp bool)
(c1 c2 c3: computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\
exec_equiv phi' phi'' c3 c3
))
(ensures (
exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))
))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2))];
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi' phi'' c3 c3)];
[SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)];
]]
= Benton2004.d_cc b c1 c2 c3 (interp phi) (interp phi') (interp phi'') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires Benton2004.RHL.exec_equiv phi phi' (Benton2004.while b c) (Benton2004.while b c))
(ensures
Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.while b c)
(Benton2004.ifthenelse b (Benton2004.seq c (Benton2004.while b c)) Benton2004.skip)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Benton2004.d_lu1",
"Benton2004.RHL.interp",
"Prims.unit",
"Benton2004.RHL.exec_equiv",
"Benton2004.while",
"Prims.squash",
"Benton2004.ifthenelse",
"Benton2004.seq",
"Benton2004.skip",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let d_lu1 (b: exp bool) (c: computation) (phi phi': gexp bool)
: Lemma (requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) =
| Benton2004.d_lu1 b c (interp phi) (interp phi') | false |
Benton2004.RHL.fst | Benton2004.RHL.d_cc | val d_cc
(b: exp bool)
(c1 c2 c3: computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\
exec_equiv phi' phi'' c3 c3
))
(ensures (
exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))
))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2))];
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi' phi'' c3 c3)];
[SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)];
]] | val d_cc
(b: exp bool)
(c1 c2 c3: computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\
exec_equiv phi' phi'' c3 c3
))
(ensures (
exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))
))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2))];
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi' phi'' c3 c3)];
[SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)];
]] | let d_cc
(b: exp bool)
(c1 c2 c3: computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\
exec_equiv phi' phi'' c3 c3
))
(ensures (
exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))
))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2))];
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi' phi'' c3 c3)];
[SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)];
]]
= Benton2004.d_cc b c1 c2 c3 (interp phi) (interp phi') (interp phi'') | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 573,
"start_col": 0,
"start_line": 556
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *)
let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi')
let d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]]
= Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'')
let d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)]
= Benton2004.d_su2 c (interp phi) (interp phi')
let d_assoc
(c1 c2 c3: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))]
= Benton2004.d_assoc c1 c2 c3 (interp phi) (interp phi') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
c1: Benton2004.computation ->
c2: Benton2004.computation ->
c3: Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool ->
phi'': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.ifthenelse b c1 c2)
(Benton2004.ifthenelse b c1 c2) /\ Benton2004.RHL.exec_equiv phi' phi'' c3 c3)
(ensures
Benton2004.RHL.exec_equiv phi
phi''
(Benton2004.seq (Benton2004.ifthenelse b c1 c2) c3)
(Benton2004.ifthenelse b (Benton2004.seq c1 c3) (Benton2004.seq c2 c3)))
[
SMTPatOr [
[
SMTPat (Benton2004.RHL.exec_equiv phi
phi''
(Benton2004.seq (Benton2004.ifthenelse b c1 c2) c3)
(Benton2004.ifthenelse b (Benton2004.seq c1 c3) (Benton2004.seq c2 c3)));
SMTPat (Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.ifthenelse b c1 c2)
(Benton2004.ifthenelse b c1 c2))
];
[
SMTPat (Benton2004.RHL.exec_equiv phi
phi''
(Benton2004.seq (Benton2004.ifthenelse b c1 c2) c3)
(Benton2004.ifthenelse b (Benton2004.seq c1 c3) (Benton2004.seq c2 c3)));
SMTPat (Benton2004.RHL.exec_equiv phi' phi'' c3 c3)
];
[
SMTPat (Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.ifthenelse b c1 c2)
(Benton2004.ifthenelse b c1 c2));
SMTPat (Benton2004.RHL.exec_equiv phi' phi'' c3 c3)
]
]
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Benton2004.d_cc",
"Benton2004.RHL.interp",
"Prims.unit",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Benton2004.ifthenelse",
"Prims.squash",
"Benton2004.seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'': gexp bool)
: Lemma
(requires
(exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\
exec_equiv phi' phi'' c3 c3))
(ensures
(exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))))
[
SMTPatOr
[
[
SMTPat
(exec_equiv phi
phi''
(seq (ifthenelse b c1 c2) c3)
(ifthenelse b (seq c1 c3) (seq c2 c3)));
SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2))
];
[
SMTPat
(exec_equiv phi
phi''
(seq (ifthenelse b c1 c2) c3)
(ifthenelse b (seq c1 c3) (seq c2 c3)));
SMTPat (exec_equiv phi' phi'' c3 c3)
];
[
SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2));
SMTPat (exec_equiv phi' phi'' c3 c3)
]
]
] =
| Benton2004.d_cc b c1 c2 c3 (interp phi) (interp phi') (interp phi'') | false |
Benton2004.RHL.fst | Benton2004.RHL.d_assoc | val d_assoc
(c1 c2 c3: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] | val d_assoc
(c1 c2 c3: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] | let d_assoc
(c1 c2 c3: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))]
= Benton2004.d_assoc c1 c2 c3 (interp phi) (interp phi') | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 554,
"start_col": 0,
"start_line": 547
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *)
let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi')
let d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]]
= Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'')
let d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)]
= Benton2004.d_su2 c (interp phi) (interp phi') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c1: Benton2004.computation ->
c2: Benton2004.computation ->
c3: Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.seq (Benton2004.seq c1 c2) c3)
(Benton2004.seq (Benton2004.seq c1 c2) c3))
(ensures
Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.seq (Benton2004.seq c1 c2) c3)
(Benton2004.seq c1 (Benton2004.seq c2 c3)))
[
SMTPat (Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.seq (Benton2004.seq c1 c2) c3)
(Benton2004.seq c1 (Benton2004.seq c2 c3)))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.d_assoc",
"Benton2004.RHL.interp",
"Prims.unit",
"Benton2004.RHL.exec_equiv",
"Benton2004.seq",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let d_assoc (c1 c2 c3: computation) (phi phi': gexp bool)
: Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] =
| Benton2004.d_assoc c1 c2 c3 (interp phi) (interp phi') | false |
Benton2004.RHL.fst | Benton2004.RHL.d_lu2 | val d_lu2
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip))))) | val d_lu2
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip))))) | let d_lu2
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip)))))
= Benton2004.d_lu2 b c (interp phi) (interp phi') | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 591,
"start_col": 0,
"start_line": 584
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *)
let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi')
let d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]]
= Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'')
let d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)]
= Benton2004.d_su2 c (interp phi) (interp phi')
let d_assoc
(c1 c2 c3: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))]
= Benton2004.d_assoc c1 c2 c3 (interp phi) (interp phi')
let d_cc
(b: exp bool)
(c1 c2 c3: computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\
exec_equiv phi' phi'' c3 c3
))
(ensures (
exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))
))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2))];
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi' phi'' c3 c3)];
[SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)];
]]
= Benton2004.d_cc b c1 c2 c3 (interp phi) (interp phi') (interp phi'')
let d_lu1
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip)))
= Benton2004.d_lu1 b c (interp phi) (interp phi') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires Benton2004.RHL.exec_equiv phi phi' (Benton2004.while b c) (Benton2004.while b c))
(ensures
Benton2004.RHL.exec_equiv phi
phi'
(Benton2004.while b c)
(Benton2004.while b (Benton2004.seq c (Benton2004.ifthenelse b c Benton2004.skip)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Benton2004.d_lu2",
"Benton2004.RHL.interp",
"Prims.unit",
"Benton2004.RHL.exec_equiv",
"Benton2004.while",
"Prims.squash",
"Benton2004.seq",
"Benton2004.ifthenelse",
"Benton2004.skip",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let d_lu2 (b: exp bool) (c: computation) (phi phi': gexp bool)
: Lemma (requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip))))) =
| Benton2004.d_lu2 b c (interp phi) (interp phi') | false |
Benton2004.RHL.fst | Benton2004.RHL.r_cbl | val r_cbl
(b: exp bool)
(c c' d : computation)
(phi phi' : gexp bool)
: Lemma
(requires (
exec_equiv
(gand phi (exp_to_gexp b Left))
phi'
c
d /\
exec_equiv
(gand phi (gnot (exp_to_gexp b Left)))
phi'
c'
d
))
(ensures (
exec_equiv
phi
phi'
(ifthenelse b c c')
d
)) | val r_cbl
(b: exp bool)
(c c' d : computation)
(phi phi' : gexp bool)
: Lemma
(requires (
exec_equiv
(gand phi (exp_to_gexp b Left))
phi'
c
d /\
exec_equiv
(gand phi (gnot (exp_to_gexp b Left)))
phi'
c'
d
))
(ensures (
exec_equiv
phi
phi'
(ifthenelse b c c')
d
)) | let r_cbl
(b: exp bool)
(c c' d : computation)
(phi phi' : gexp bool)
: Lemma
(requires (
exec_equiv
(gand phi (exp_to_gexp b Left))
phi'
c
d /\
exec_equiv
(gand phi (gnot (exp_to_gexp b Left)))
phi'
c'
d
))
(ensures (
exec_equiv
phi
phi'
(ifthenelse b c c')
d
))
= (* NOTE: the following let _ are necessary, and must be stated in this form instead of asserts alone, the latter seeming ineffective *)
let _ : squash (forall s1 s2 . holds (interp (gand phi (exp_to_gexp b Left))) s1 s2 <==> holds (interp phi) s1 s2 /\ fst (reify_exp b s1) == true) =
assert (forall s1 s2 . holds (interp (gand phi (exp_to_gexp b Left))) s1 s2 <==> holds (interp phi) s1 s2 /\ fst (reify_exp b s1) == true)
in
let _ : squash (forall s1 s2 . holds (interp (gand phi (gnot (exp_to_gexp b Left)))) s1 s2 <==> holds (interp phi) s1 s2 /\ ~ (fst (reify_exp b s1) == true)) =
assert (forall s1 s2 . holds (interp (gand phi (gnot (exp_to_gexp b Left)))) s1 s2 <==> holds (interp phi) s1 s2 /\ ~ (fst (reify_exp b s1) == true))
in
() | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 4,
"end_line": 660,
"start_col": 0,
"start_line": 628
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= ()
let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else ()
let holds_interp_flip (phi: gexp bool) : Lemma
(forall s1 s2 . holds (interp (flip phi)) s1 s2 <==> holds (Benton2004.flip (interp phi)) s1 s2)
[SMTPat (holds (interp (flip phi)))]
= Benton2004.holds_flip (interp phi)
let exec_equiv_flip
(p p': gexp bool)
(f f' : computation)
: Lemma
(exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f)
[SMTPat (exec_equiv (flip p) (flip p') f f')]
= holds_interp_flip p;
holds_interp_flip p';
exec_equiv_flip (interp p) (interp p') f f'
let r_while_terminates
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0'
))
(ensures (
terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'
))
= let phi = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c = gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
let phi_c' = gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) in
Classical.forall_intro (Classical.move_requires (r_while_terminates' b b' c c' phi phi_c phi_c' s0 s0'));
Classical.forall_intro (Classical.move_requires (r_while_terminates' b' b c' c (flip phi) (flip phi_c) (flip phi_c') s0' s0))
let rec r_while_correct
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true
))
(ensures (
holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel s0') in
r_while_correct b b' c c' p s1 s1' (fuel - 1)
else ()
let rec r_while
(b b' : exp bool)
(c c' : computation)
(p: gexp bool)
: Lemma
(requires (
exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c'
))
(ensures (
exec_equiv (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right)))) (while b c) (while b' c')
))
= let g (s0 s0':heap)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0') ==>
(terminates_on (reify_computation (while b c)) s0 <==>
terminates_on (reify_computation (while b' c')) s0'))
= Classical.move_requires (r_while_terminates b b' c c' p s0) s0'
in
let h (s0 s0':heap) (fuel:nat)
:Lemma ((exec_equiv (gand p (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right))) c c' /\
holds (interp (gand p (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true /\
fst (reify_computation (while b' c') fuel s0') == true) ==>
(holds (interp (gand p (gnot (gor (exp_to_gexp b Left) (exp_to_gexp b' Right))))) (snd (reify_computation (while b c) fuel s0)) (snd (reify_computation (while b' c') fuel s0'))))
= Classical.move_requires (r_while_correct b b' c c' p s0 s0') fuel
in
Classical.forall_intro_2 g;
Classical.forall_intro_3 h
(* Aparte: 4.4 How to prove is_per *)
let is_per_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(is_per (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let is_per_gand_exp_to_gexp
(b: exp bool)
: Lemma
(is_per (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
let is_per_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2))
(ensures (is_per (gand e1 e2)))
= assert (forall s1 s2 .{:pattern (interp (gand e1 e2) s1 s2)} holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
(* FIXME: holds but not replayable
let is_per_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ (forall s1 s2 . ~ (holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2))))
(ensures (is_per (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_sym
(p p': gexp bool)
(f f' : computation)
: Lemma
(requires (is_per p /\ is_per p'))
(ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f))
[SMTPat (exec_equiv p p' f f'); SMTPat (is_per p); SMTPat (is_per p')]
= exec_equiv_sym (interp p) (interp p') f f'
(* Aparte: 4.4 How to prove interpolable *)
let interpolable_geq_exp_to_gexp
(#t: eqtype)
(e: exp t)
: Lemma
(interpolable (geq (exp_to_gexp e Left) (exp_to_gexp e Right)))
= ()
let interpolable_gand_exp_to_gexp
(b: exp bool)
: Lemma
(interpolable (gand (exp_to_gexp b Left) (exp_to_gexp b Right)))
= ()
(* FIXME: holds but not replayable
let interpolable_gand
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gand e1 e2)))
= assert (forall s1 s2 . holds (interp (gand e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 /\ holds (interp e2) s1 s2)
let interpolable_gor
(e1 e2 : gexp bool)
: Lemma
(requires (is_per e1 /\ is_per e2 /\ interpolable e1 /\ interpolable e2))
(ensures (interpolable (gor e1 e2)))
= assert (forall s1 s2 . holds (interp (gor e1 e2)) s1 s2 <==> holds (interp e1) s1 s2 \/ holds (interp e2) s1 s2)
*)
let r_trans
(p p' : gexp bool)
(c1 c2 c3 : computation)
: Lemma
(requires (
is_per p' /\
interpolable p /\
exec_equiv p p' c1 c2 /\
exec_equiv p p' c2 c3
))
(ensures (exec_equiv p p' c1 c3))
[SMTPatOr [
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
[SMTPat (exec_equiv p p' c1 c3); SMTPat (exec_equiv p p' c2 c3); SMTPat (is_per p'); SMTPat (interpolable p)];
]]
= exec_equiv_trans (interp p) (interp p') c1 c2 c3
(* 4.2.1 Basic equations *)
let d_su1
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq skip c) c))
[SMTPat (exec_equiv phi phi' (seq skip c) c)]
= Benton2004.d_su1 c (interp phi) (interp phi')
let d_su1'
(c c' c'' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' c skip /\
exec_equiv phi' phi'' c' c''
))
(ensures (exec_equiv phi phi'' (seq c c') c''))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi phi' c skip)];
[SMTPat (exec_equiv phi phi'' (seq c c') c''); SMTPat (exec_equiv phi' phi'' c' c'')];
[SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi' c skip)];
]]
= Benton2004.d_su1' c c' c'' (interp phi) (interp phi') (interp phi'')
let d_su2
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' c c))
(ensures (exec_equiv phi phi' (seq c skip) c))
[SMTPat (exec_equiv phi phi' (seq c skip) c)]
= Benton2004.d_su2 c (interp phi) (interp phi')
let d_assoc
(c1 c2 c3: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3)))
(ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3))))
[SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))]
= Benton2004.d_assoc c1 c2 c3 (interp phi) (interp phi')
let d_cc
(b: exp bool)
(c1 c2 c3: computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\
exec_equiv phi' phi'' c3 c3
))
(ensures (
exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))
))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2))];
[SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))); SMTPat (exec_equiv phi' phi'' c3 c3)];
[SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)];
]]
= Benton2004.d_cc b c1 c2 c3 (interp phi) (interp phi') (interp phi'')
let d_lu1
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip)))
= Benton2004.d_lu1 b c (interp phi) (interp phi')
let d_lu2
(b: exp bool)
(c: computation)
(phi phi' : gexp bool)
: Lemma
(requires (exec_equiv phi phi' (while b c) (while b c)))
(ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip)))))
= Benton2004.d_lu2 b c (interp phi) (interp phi')
(* 4.2.2 Optimizing Transformations *)
(* Falsity *)
let r_f
(c c' : computation)
(phi: gexp bool)
: Lemma
(ensures (
exec_equiv
(gconst false)
phi
c
c'
))
= ()
(* Dead assignment *)
let r_dassl
(x: var)
(e: exp int)
(phi: gexp bool)
: Lemma
(ensures (
exec_equiv
(gsubst phi x Left (exp_to_gexp e Left))
phi
(assign x e)
skip
))
= ()
(* Common branch *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
c': Benton2004.computation ->
d: Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv (Benton2004.RHL.gand phi
(Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left))
phi'
c
d /\
Benton2004.RHL.exec_equiv (Benton2004.RHL.gand phi
(Benton2004.RHL.gnot (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)))
phi'
c'
d) (ensures Benton2004.RHL.exec_equiv phi phi' (Benton2004.ifthenelse b c c') d) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Prims.squash",
"Prims.l_Forall",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Prims.l_iff",
"Benton2004.Aux.holds",
"Benton2004.RHL.interp",
"Benton2004.RHL.gand",
"Benton2004.RHL.gnot",
"Benton2004.RHL.exp_to_gexp",
"Benton2004.RHL.Left",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2",
"FStar.Pervasives.Native.fst",
"Benton2004.reify_exp",
"Prims._assert",
"Prims.unit",
"Benton2004.RHL.exec_equiv",
"Benton2004.ifthenelse",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let r_cbl (b: exp bool) (c c' d: computation) (phi phi': gexp bool)
: Lemma
(requires
(exec_equiv (gand phi (exp_to_gexp b Left)) phi' c d /\
exec_equiv (gand phi (gnot (exp_to_gexp b Left))) phi' c' d))
(ensures (exec_equiv phi phi' (ifthenelse b c c') d)) =
| let _:squash (forall s1 s2.
holds (interp (gand phi (exp_to_gexp b Left))) s1 s2 <==>
holds (interp phi) s1 s2 /\ fst (reify_exp b s1) == true) =
assert (forall s1 s2.
holds (interp (gand phi (exp_to_gexp b Left))) s1 s2 <==>
holds (interp phi) s1 s2 /\ fst (reify_exp b s1) == true)
in
let _:squash (forall s1 s2.
holds (interp (gand phi (gnot (exp_to_gexp b Left)))) s1 s2 <==>
holds (interp phi) s1 s2 /\ ~(fst (reify_exp b s1) == true)) =
assert (forall s1 s2.
holds (interp (gand phi (gnot (exp_to_gexp b Left)))) s1 s2 <==>
holds (interp phi) s1 s2 /\ ~(fst (reify_exp b s1) == true))
in
() | false |
Vale.Curve25519.X64.FastUtil.fst | Vale.Curve25519.X64.FastUtil.va_qcode_Fast_mul1 | val va_qcode_Fast_mul1 (va_mods: va_mods_t) (dst_b inA_b: buffer64)
: (va_quickCode unit (va_code_Fast_mul1 ())) | val va_qcode_Fast_mul1 (va_mods: va_mods_t) (dst_b inA_b: buffer64)
: (va_quickCode unit (va_code_Fast_mul1 ())) | let va_qcode_Fast_mul1 (va_mods:va_mods_t) (dst_b:buffer64) (inA_b:buffer64) : (va_quickCode unit
(va_code_Fast_mul1 ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(a0:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read inA_b 0 (va_get_mem_heaplet 0 va_s)
in let (a1:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read inA_b 1 (va_get_mem_heaplet 0
va_s) in let (a2:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read inA_b 2
(va_get_mem_heaplet 0 va_s) in let (a3:Vale.Def.Types_s.nat64) = Vale.X64.Decls.buffer64_read
inA_b 3 (va_get_mem_heaplet 0 va_s) in let (a:Prims.nat) = Vale.Curve25519.Fast_defs.pow2_four
a0 a1 a2 a3 in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 91 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_:unit) -> Vale.Arch.Types.xor_lemmas ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 93 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 inA_b 0 Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64 (va_op_dst_opr64_reg64 rR9) (va_op_dst_opr64_reg64 rR8) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 Secret)) (fun (va_s:va_state) _ -> let
(va_arg48:Vale.Def.Types_s.nat64) = va_get_reg64 rRdx va_s in let
(va_arg47:Vale.Def.Types_s.nat64) = va_get_reg64 rR8 va_s in let
(va_arg46:Vale.Def.Types_s.nat64) = va_get_reg64 rR9 va_s in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 93 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_:unit) -> Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds va_arg46 va_arg47
va_arg48 a0) (let (old_r8:nat64) = va_get_reg64 rR8 va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 94 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rR8) 0 Secret dst_b 0) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 95 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Xor64 (va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rR8)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 96 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 8 inA_b 1 Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 96 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64 (va_op_dst_opr64_reg64 rR11) (va_op_dst_opr64_reg64 rR10) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 8 Secret)) (fun (va_s:va_state) _ -> let
(va_arg45:Vale.Def.Types_s.nat64) = va_get_reg64 rRdx va_s in let
(va_arg44:Vale.Def.Types_s.nat64) = va_get_reg64 rR10 va_s in let
(va_arg43:Vale.Def.Types_s.nat64) = va_get_reg64 rR11 va_s in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 96 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_:unit) -> Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds va_arg43 va_arg44
va_arg45 a1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 97 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Add64Wrap (va_op_dst_opr64_reg64 rR10) (va_op_opr64_reg64 rR9)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 98 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rR10) 8 Secret dst_b 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 99 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 16 inA_b 2 Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 99 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64 (va_op_dst_opr64_reg64 rR13) (va_op_dst_opr64_reg64 rRbx) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 16 Secret)) (fun (va_s:va_state) _ ->
let (va_arg42:Vale.Def.Types_s.nat64) = va_get_reg64 rRdx va_s in let
(va_arg41:Vale.Def.Types_s.nat64) = va_get_reg64 rRbx va_s in let
(va_arg40:Vale.Def.Types_s.nat64) = va_get_reg64 rR13 va_s in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 99 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_:unit) -> Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds va_arg40 va_arg41
va_arg42 a2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 100 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Adcx64Wrap (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR11)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 101 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rRbx) 16 Secret dst_b 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma (va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 24 inA_b 3 Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 102 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64 (va_op_dst_opr64_reg64 rRax) (va_op_dst_opr64_reg64 rR14) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 24 Secret)) (fun (va_s:va_state) _ ->
let (va_arg39:Vale.Def.Types_s.nat64) = va_get_reg64 rRdx va_s in let
(va_arg38:Vale.Def.Types_s.nat64) = va_get_reg64 rR14 va_s in let
(va_arg37:Vale.Def.Types_s.nat64) = va_get_reg64 rRax va_s in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 102 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_:unit) -> Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds va_arg37 va_arg38
va_arg39 a3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 103 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Adcx64Wrap (va_op_dst_opr64_reg64 rR14) (va_op_opr64_reg64 rR13)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 104 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rR14) 24 Secret dst_b 3) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 105 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Adcx64Wrap (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR8)) (fun (va_s:va_state)
_ -> let (carry_bit:Vale.Curve25519.Fast_defs.bit) = Vale.Curve25519.Fast_defs.bool_bit
(Vale.X64.Decls.cf (va_get_flags va_s)) in va_qAssert va_range1
"***** PRECONDITION NOT MET AT line 108 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(carry_bit == 0) (let (va_arg36:prop) = va_mul_nat a (va_get_reg64 rRdx va_s) == 0 +
Vale.Curve25519.Fast_defs.pow2_four (va_mul_nat (va_get_reg64 rRdx va_s) a0) (va_mul_nat
(va_get_reg64 rRdx va_s) a1) (va_mul_nat (va_get_reg64 rRdx va_s) a2) (va_mul_nat (va_get_reg64
rRdx va_s) a3) in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 109 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_:unit) -> assert_by_tactic va_arg36 int_canon) (va_QEmpty (()))))))))))))))))))))))))))) | {
"file_name": "obj/Vale.Curve25519.X64.FastUtil.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 99,
"end_line": 168,
"start_col": 0,
"start_line": 79
} | module Vale.Curve25519.X64.FastUtil
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open FStar.Tactics
open Vale.Curve25519.Fast_defs
open Vale.Curve25519.Fast_lemmas_external
open Vale.Curve25519.FastUtil_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 60"
//-- Fast_mul1
#push-options "--z3rlimit 600"
val va_code_Fast_mul1 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Fast_mul1 () =
(va_Block (va_CCons (va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx64 (va_op_dst_opr64_reg64
rR9) (va_op_dst_opr64_reg64 rR8) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi) 0 Secret)) (va_CCons (va_code_Store64_buffer
(va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rR8) 0
Secret) (va_CCons (va_code_Xor64 (va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rR8)) (va_CCons
(va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx64 (va_op_dst_opr64_reg64 rR11)
(va_op_dst_opr64_reg64 rR10) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi) 8 Secret)) (va_CCons (va_code_Add64Wrap (va_op_dst_opr64_reg64 rR10)
(va_op_opr64_reg64 rR9)) (va_CCons (va_code_Store64_buffer (va_op_heaplet_mem_heaplet 0)
(va_op_reg_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rR10) 8 Secret) (va_CCons
(va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx64 (va_op_dst_opr64_reg64 rR13)
(va_op_dst_opr64_reg64 rRbx) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi) 16 Secret)) (va_CCons (va_code_Adcx64Wrap (va_op_dst_opr64_reg64 rRbx)
(va_op_opr64_reg64 rR11)) (va_CCons (va_code_Store64_buffer (va_op_heaplet_mem_heaplet 0)
(va_op_reg_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rRbx) 16 Secret) (va_CCons
(va_code_Mem64_lemma ()) (va_CCons (va_code_Mulx64 (va_op_dst_opr64_reg64 rRax)
(va_op_dst_opr64_reg64 rR14) (va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi) 24 Secret)) (va_CCons (va_code_Adcx64Wrap (va_op_dst_opr64_reg64 rR14)
(va_op_opr64_reg64 rR13)) (va_CCons (va_code_Store64_buffer (va_op_heaplet_mem_heaplet 0)
(va_op_reg_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rR14) 24 Secret) (va_CCons
(va_code_Adcx64Wrap (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR8)) (va_CNil
())))))))))))))))))))
val va_codegen_success_Fast_mul1 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Fast_mul1 () =
(va_pbool_and (va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx64
(va_op_dst_opr64_reg64 rR9) (va_op_dst_opr64_reg64 rR8) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 0 Secret)) (va_pbool_and
(va_codegen_success_Store64_buffer (va_op_heaplet_mem_heaplet 0) (va_op_reg_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rR8) 0 Secret) (va_pbool_and (va_codegen_success_Xor64
(va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rR8)) (va_pbool_and
(va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx64
(va_op_dst_opr64_reg64 rR11) (va_op_dst_opr64_reg64 rR10) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 8 Secret)) (va_pbool_and
(va_codegen_success_Add64Wrap (va_op_dst_opr64_reg64 rR10) (va_op_opr64_reg64 rR9))
(va_pbool_and (va_codegen_success_Store64_buffer (va_op_heaplet_mem_heaplet 0)
(va_op_reg_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rR10) 8 Secret) (va_pbool_and
(va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx64
(va_op_dst_opr64_reg64 rR13) (va_op_dst_opr64_reg64 rRbx) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 16 Secret)) (va_pbool_and
(va_codegen_success_Adcx64Wrap (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR11))
(va_pbool_and (va_codegen_success_Store64_buffer (va_op_heaplet_mem_heaplet 0)
(va_op_reg_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rRbx) 16 Secret) (va_pbool_and
(va_codegen_success_Mem64_lemma ()) (va_pbool_and (va_codegen_success_Mulx64
(va_op_dst_opr64_reg64 rRax) (va_op_dst_opr64_reg64 rR14) (va_opr_code_Mem64
(va_op_heaplet_mem_heaplet 0) (va_op_reg64_reg64 rRsi) 24 Secret)) (va_pbool_and
(va_codegen_success_Adcx64Wrap (va_op_dst_opr64_reg64 rR14) (va_op_opr64_reg64 rR13))
(va_pbool_and (va_codegen_success_Store64_buffer (va_op_heaplet_mem_heaplet 0)
(va_op_reg_opr64_reg64 rRdi) (va_op_reg_opr64_reg64 rR14) 24 Secret) (va_pbool_and
(va_codegen_success_Adcx64Wrap (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR8)) (va_ttrue
())))))))))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.FastUtil_helpers.fsti.checked",
"Vale.Curve25519.Fast_lemmas_external.fsti.checked",
"Vale.Curve25519.Fast_defs.fst.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Curve25519.X64.FastUtil.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Curve25519.FastUtil_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Curve25519.Fast_lemmas_external",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Curve25519.Fast_defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Curve25519.Fast_defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Curve25519.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Curve25519.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 600,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
va_mods: Vale.X64.QuickCode.va_mods_t ->
dst_b: Vale.X64.Memory.buffer64 ->
inA_b: Vale.X64.Memory.buffer64
-> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.Curve25519.X64.FastUtil.va_code_Fast_mul1 ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.QuickCode.va_mods_t",
"Vale.X64.Memory.buffer64",
"Vale.X64.QuickCodes.qblock",
"Prims.unit",
"Prims.Cons",
"Vale.X64.Decls.va_code",
"Vale.X64.InsMem.va_code_Mem64_lemma",
"Vale.X64.InsBasic.va_code_Mulx64",
"Vale.X64.Decls.va_op_dst_opr64_reg64",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rR8",
"Vale.X64.Decls.va_opr_code_Mem64",
"Vale.X64.Decls.va_op_heaplet_mem_heaplet",
"Vale.X64.Decls.va_op_reg64_reg64",
"Vale.X64.Machine_s.rRsi",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.InsMem.va_code_Store64_buffer",
"Vale.X64.Decls.va_op_reg_opr64_reg64",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.InsBasic.va_code_Xor64",
"Vale.X64.Decls.va_op_opr64_reg64",
"Vale.X64.Machine_s.rR11",
"Vale.X64.Machine_s.rR10",
"Vale.X64.InsBasic.va_code_Add64Wrap",
"Vale.X64.Machine_s.rR13",
"Vale.X64.Machine_s.rRbx",
"Vale.X64.InsBasic.va_code_Adcx64Wrap",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Machine_s.rR14",
"Prims.Nil",
"Vale.X64.Machine_s.precode",
"Vale.X64.Decls.ins",
"Vale.X64.Decls.ocmp",
"Vale.X64.Decls.va_state",
"Vale.X64.QuickCodes.va_qPURE",
"Prims.pure_post",
"Prims.l_and",
"Prims.l_True",
"Prims.l_Forall",
"Prims.l_imp",
"Vale.Def.Words_s.nat32",
"Prims.eq2",
"Vale.Def.Types_s.ixor",
"Prims.int",
"Vale.Def.Words_s.nat64",
"Vale.X64.QuickCodes.va_range1",
"Vale.Arch.Types.xor_lemmas",
"Vale.X64.QuickCodes.va_QSeq",
"Vale.X64.InsMem.va_quick_Mem64_lemma",
"Vale.X64.QuickCodes.va_QBind",
"Vale.X64.InsBasic.va_quick_Mulx64",
"Prims.op_Addition",
"Prims.op_Multiply",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds",
"Vale.X64.InsMem.va_quick_Store64_buffer",
"Vale.X64.InsBasic.va_quick_Xor64",
"Vale.X64.InsBasic.va_quick_Add64Wrap",
"Vale.X64.InsBasic.va_quick_Adcx64Wrap",
"Vale.X64.QuickCodes.va_qAssert",
"FStar.Tactics.Effect.with_tactic",
"Vale.Curve25519.FastUtil_helpers.int_canon",
"Prims.squash",
"FStar.Tactics.Effect.assert_by_tactic",
"Vale.X64.QuickCodes.va_QEmpty",
"Prims.prop",
"Vale.X64.Decls.va_mul_nat",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRdx",
"Vale.Curve25519.Fast_defs.pow2_four",
"Vale.Curve25519.Fast_defs.bit",
"Vale.Curve25519.Fast_defs.bool_bit",
"Vale.X64.Decls.cf",
"Vale.X64.Decls.va_get_flags",
"Vale.X64.QuickCodes.quickCodes",
"Prims.nat",
"Vale.X64.Decls.buffer64_read",
"Vale.X64.Decls.va_get_mem_heaplet",
"Vale.X64.State.vale_state",
"Vale.X64.QuickCode.va_quickCode",
"Vale.Curve25519.X64.FastUtil.va_code_Fast_mul1"
] | [] | false | false | false | false | false | let va_qcode_Fast_mul1 (va_mods: va_mods_t) (dst_b inA_b: buffer64)
: (va_quickCode unit (va_code_Fast_mul1 ())) =
| (qblock va_mods
(fun (va_s: va_state) ->
let va_old_s:va_state = va_s in
let a0:Vale.Def.Types_s.nat64 =
Vale.X64.Decls.buffer64_read inA_b 0 (va_get_mem_heaplet 0 va_s)
in
let a1:Vale.Def.Types_s.nat64 =
Vale.X64.Decls.buffer64_read inA_b 1 (va_get_mem_heaplet 0 va_s)
in
let a2:Vale.Def.Types_s.nat64 =
Vale.X64.Decls.buffer64_read inA_b 2 (va_get_mem_heaplet 0 va_s)
in
let a3:Vale.Def.Types_s.nat64 =
Vale.X64.Decls.buffer64_read inA_b 3 (va_get_mem_heaplet 0 va_s)
in
let a:Prims.nat = Vale.Curve25519.Fast_defs.pow2_four a0 a1 a2 a3 in
va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 91 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_: unit) -> Vale.Arch.Types.xor_lemmas ())
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 93 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi)
0
inA_b
0
Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64 (va_op_dst_opr64_reg64 rR9)
(va_op_dst_opr64_reg64 rR8)
(va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi)
0
Secret))
(fun (va_s: va_state) _ ->
let va_arg48:Vale.Def.Types_s.nat64 = va_get_reg64 rRdx va_s in
let va_arg47:Vale.Def.Types_s.nat64 = va_get_reg64 rR8 va_s in
let va_arg46:Vale.Def.Types_s.nat64 = va_get_reg64 rR9 va_s in
va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 93 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_: unit) ->
Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds va_arg46
va_arg47
va_arg48
a0)
(let old_r8:nat64 = va_get_reg64 rR8 va_s in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 94 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer (va_op_heaplet_mem_heaplet 0)
(va_op_reg_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rR8)
0
Secret
dst_b
0)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 95 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Xor64 (va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rR8))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 96 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi)
8
inA_b
1
Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 96 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64 (va_op_dst_opr64_reg64 rR11)
(va_op_dst_opr64_reg64 rR10)
(va_opr_code_Mem64 (va_op_heaplet_mem_heaplet 0)
(va_op_reg64_reg64 rRsi)
8
Secret))
(fun (va_s: va_state) _ ->
let va_arg45:Vale.Def.Types_s.nat64 =
va_get_reg64 rRdx va_s
in
let va_arg44:Vale.Def.Types_s.nat64 =
va_get_reg64 rR10 va_s
in
let va_arg43:Vale.Def.Types_s.nat64 =
va_get_reg64 rR11 va_s
in
va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 96 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_: unit) ->
Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds
va_arg43
va_arg44
va_arg45
a1)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 97 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Add64Wrap (va_op_dst_opr64_reg64 rR10)
(va_op_opr64_reg64 rR9))
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 98 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer (va_op_heaplet_mem_heaplet
0)
(va_op_reg_opr64_reg64 rRdi)
(va_op_reg_opr64_reg64 rR10)
8
Secret
dst_b
1)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 99 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma (va_op_heaplet_mem_heaplet
0)
(va_op_reg64_reg64 rRsi)
16
inA_b
2
Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 99 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64 (va_op_dst_opr64_reg64
rR13)
(va_op_dst_opr64_reg64 rRbx)
(va_opr_code_Mem64 (va_op_heaplet_mem_heaplet
0)
(va_op_reg64_reg64 rRsi)
16
Secret))
(fun (va_s: va_state) _ ->
let va_arg42:Vale.Def.Types_s.nat64
=
va_get_reg64 rRdx va_s
in
let va_arg41:Vale.Def.Types_s.nat64
=
va_get_reg64 rRbx va_s
in
let va_arg40:Vale.Def.Types_s.nat64
=
va_get_reg64 rR13 va_s
in
va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 99 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun (_: unit) ->
Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds
va_arg40
va_arg41
va_arg42
a2)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 100 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Adcx64Wrap (va_op_dst_opr64_reg64
rRbx)
(va_op_opr64_reg64 rR11)
)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 101 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer
(va_op_heaplet_mem_heaplet
0)
(va_op_reg_opr64_reg64
rRdi)
(va_op_reg_opr64_reg64
rRbx)
16
Secret
dst_b
2)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mem64_lemma
(va_op_heaplet_mem_heaplet
0)
(va_op_reg64_reg64
rRsi)
24
inA_b
3
Secret)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 102 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Mulx64
(va_op_dst_opr64_reg64
rRax)
(va_op_dst_opr64_reg64
rR14)
(va_opr_code_Mem64
(va_op_heaplet_mem_heaplet
0)
(va_op_reg64_reg64
rRsi
)
24
Secret))
(fun
(va_s:
va_state)
_
->
let va_arg39:Vale.Def.Types_s.nat64
=
va_get_reg64
rRdx
va_s
in
let va_arg38:Vale.Def.Types_s.nat64
=
va_get_reg64
rR14
va_s
in
let va_arg37:Vale.Def.Types_s.nat64
=
va_get_reg64
rRax
va_s
in
va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 102 column 99 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(fun
(_:
unit
)
->
Vale.Curve25519.Fast_lemmas_external.lemma_prod_bounds
va_arg37
va_arg38
va_arg39
a3)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 103 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Adcx64Wrap
(va_op_dst_opr64_reg64
rR14
)
(va_op_opr64_reg64
rR13
))
(va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 104 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(va_quick_Store64_buffer
(
va_op_heaplet_mem_heaplet
0
)
(
va_op_reg_opr64_reg64
rRdi
)
(
va_op_reg_opr64_reg64
rR14
)
24
Secret
dst_b
3
)
(va_QBind
va_range1
"***** PRECONDITION NOT MET AT line 105 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(
va_quick_Adcx64Wrap
(
va_op_dst_opr64_reg64
rRax
)
(
va_op_opr64_reg64
rR8
)
)
(
fun
(
va_s:
va_state
)
_
->
let
carry_bit:Vale.Curve25519.Fast_defs.bit
=
Vale.Curve25519.Fast_defs.bool_bit
(
Vale.X64.Decls.cf
(
va_get_flags
va_s
)
)
in
va_qAssert
va_range1
"***** PRECONDITION NOT MET AT line 108 column 5 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(
carry_bit ==
0
)
(
let
va_arg36:prop
=
va_mul_nat
a
(
va_get_reg64
rRdx
va_s
)
==
0 +
Vale.Curve25519.Fast_defs.pow2_four
(
va_mul_nat
(
va_get_reg64
rRdx
va_s
)
a0
)
(
va_mul_nat
(
va_get_reg64
rRdx
va_s
)
a1
)
(
va_mul_nat
(
va_get_reg64
rRdx
va_s
)
a2
)
(
va_mul_nat
(
va_get_reg64
rRdx
va_s
)
a3
)
in
va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 109 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/rfc7748/curve25519/x64/Vale.Curve25519.X64.FastUtil.vaf *****"
(
fun
(
_:
unit
)
->
assert_by_tactic
va_arg36
int_canon
)
(
va_QEmpty
(
()
)
)
)
)
))
))))))))))
))))))))))) | false |
Benton2004.RHL.fst | Benton2004.RHL.r_while_terminates' | val r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel) | val r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel) | let rec r_while_terminates'
(b b' : exp bool)
(c c' : computation)
(phi phi_c phi_c': gexp bool)
(s0 s0' : heap)
(fuel: nat)
: Lemma
(requires (
included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\
exec_equiv phi_c phi_c' c c' /\
holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true
))
(ensures (
terminates_on (reify_computation (while b' c')) s0'
))
(decreases fuel)
= let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then begin
// let s1 = snd (reify_computation c fuel s0) in
assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g
(fuel0 : nat)
: Lemma
(requires (fst (fc' fuel0 s0') == true))
(ensures (terminates_on (f') s0'))
= let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g'
(fuel2 : nat)
: Lemma
(requires (fst (f' fuel2 s1') == true))
(ensures (terminates_on (f') s0'))
= let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)
end else () | {
"file_name": "examples/rel/Benton2004.RHL.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 328,
"start_col": 0,
"start_line": 269
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL
(* Relational Hoare Logic (Section 4) *)
let gsubst_gconst (#t: Type0) (n: t) (x: var) (side: pos) (ge' : gexp int): Lemma
(forall h1 h2. (gsubst (gconst n) x side ge') h1 h2 == (gconst n) h1 h2)
[SMTPat (gsubst (gconst n) x side ge')]
= ()
let gsubst_gvar_same (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gvar x side) x side ge') h1 h2 == ge' h1 h2)
[SMTPat (gsubst (gvar x side) x side ge')]
= ()
let gsubst_gvar_other (x x': var) (side side': pos) (ge': gexp int) : Lemma
(requires (x <> x' \/ side <> side'))
(ensures (forall h1 h2. (gsubst (gvar x side) x' side' ge') h1 h2 == (gvar x side) h1 h2))
[SMTPat (gsubst (gvar x side) x' side' ge')]
= ()
let gsubst_gop (#from #to: Type0) (op: (from -> from -> GTot to)) (ge1 ge2: gexp from) (x: var) (side: pos) (ge': gexp int) : Lemma
(forall h1 h2. (gsubst (gop op ge1 ge2) x side ge') h1 h2 ==
(gop op (gsubst ge1 x side ge') (gsubst ge2 x side ge')) h1 h2)
[SMTPat (gsubst (gop op ge1 ge2) x side ge')]
= ()
let holds_interp
(ge: gexp bool)
(s1 s2: heap)
: Lemma
(holds (interp ge) s1 s2 <==> ge s1 s2 == true)
[SMTPat (holds (interp ge) s1 s2)]
= holds_equiv (interp ge) s1 s2
let exec_equiv
(p p' : gexp bool)
(f f' : computation)
: GTot Type0
= Benton2004.exec_equiv (interp p) (interp p') f f'
let exec_equiv_elim
(p p' : gexp bool)
(f f' : computation)
: Lemma
(requires (exec_equiv p p' f f'))
(ensures (Benton2004.exec_equiv (interp p) (interp p') f f'))
= ()
let r_skip
(p: gexp bool)
: Lemma
(exec_equiv p p skip skip)
[SMTPat (exec_equiv p p skip skip)]
= d_skip (interp p)
let exp_to_gexp_const
(#t: Type0)
(c: t)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (const c) side) h1 h2 == (gconst c) h1 h2)
[SMTPat (exp_to_gexp (const c) side)]
= ()
let exp_to_gexp_evar
(x: var)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (evar x) side) h1 h2 == (gvar x side) h1 h2)
[SMTPat (exp_to_gexp (evar x) side)]
= ()
let exp_to_gexp_eop
(#from #to: Type0)
(op: (from -> from -> Tot to))
(e1 e2: exp from)
(side: pos)
: Lemma
(forall h1 h2. (exp_to_gexp (eop op e1 e2) side) h1 h2 == (gop op (exp_to_gexp e1 side) (exp_to_gexp e2 side)) h1 h2)
[SMTPat (exp_to_gexp (eop op e1 e2) side)]
= ()
#set-options "--z3rlimit 50 --max_fuel 2 --max_ifuel 1 --z3cliopt smt.qi.eager_threshold=100"
let holds_gand (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gand b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 /\ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gand b1 b2)))]
= ()
let gsubst_gand (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gand b1 b2) x side e) h1 h2 == (gand (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gand b1 b2) x side e)]
= ()
let holds_gor (b1 b2 : gexp bool) : Lemma
(forall s1 s2 . holds (interp (gor b1 b2)) s1 s2 <==> holds (interp b1) s1 s2 \/ holds (interp b2) s1 s2)
[SMTPat (holds (interp (gor b1 b2)))]
= ()
let gsubst_gor (b1 b2: gexp bool) x side e : Lemma
(forall h1 h2. (gsubst (gor b1 b2) x side e) h1 h2 == (gor (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (gor b1 b2) x side e)]
= ()
let holds_gnot (b: gexp bool) : Lemma
(forall s1 s2 . holds (interp (gnot b)) s1 s2 <==> ~ (holds (interp b) s1 s2))
[SMTPat (holds (interp (gnot b)))]
= ()
let holds_geq (#t: eqtype) (e1 e2 : gexp t) : Lemma
(forall s1 s2 . holds (interp (geq e1 e2)) s1 s2 <==> e1 s1 s2 == e2 s1 s2)
[SMTPat (holds (interp (geq e1 e2)))]
= ()
let gsubst_geq (#t: eqtype) (b1 b2: gexp t) x side e : Lemma
(forall h1 h2. (gsubst (geq b1 b2) x side e) h1 h2 == (geq (gsubst b1 x side e) (gsubst b2 x side e)) h1 h2)
[SMTPat (gsubst (geq b1 b2) x side e)]
= ()
let holds_exp_to_gexp_left
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Left)) s1 s2 <==> fst (reify_exp e s1) == true)
[SMTPat (holds (interp (exp_to_gexp e Left)))]
= ()
let holds_exp_to_gexp_right
(e: exp bool)
: Lemma
(forall s1 s2 . holds (interp (exp_to_gexp e Right)) s1 s2 <==> fst (reify_exp e s2) == true)
[SMTPat (holds (interp (exp_to_gexp e Right)))]
= ()
let holds_r_if_precond_true
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_true b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == true /\
fst (reify_exp b' s2) == true
))
= ()
let holds_r_if_precond_false
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond_false b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
( ~ (fst (reify_exp b s1) == true \/ fst (reify_exp b' s2) == true))
))
= ()
let holds_r_if_precond
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(forall s1 s2 .
holds (interp (r_if_precond b b' c c' d d' p p')) s1 s2 <==> (
holds (interp p) s1 s2 /\
fst (reify_exp b s1) == fst (reify_exp b' s2)
))
= ()
let r_if
(b b': exp bool)
(c c' d d' : computation)
(p p' : gexp bool)
: Lemma
(requires (
exec_equiv
(r_if_precond_true b b' c c' d d' p p')
p'
c
c' /\
exec_equiv
(r_if_precond_false b b' c c' d d' p p')
p'
d
d'
))
(ensures (
exec_equiv
(r_if_precond b b' c c' d d' p p')
p'
(ifthenelse b c d)
(ifthenelse b' c' d')
))
= holds_r_if_precond_true b b' c c' d d' p p';
holds_r_if_precond_false b b' c c' d d' p p';
holds_r_if_precond b b' c c' d d' p p'
let r_seq
(p0 p1 p2 : gexp bool)
(c01 c01' c12 c12' : computation)
: Lemma
(requires (
exec_equiv p0 p1 c01 c01' /\
exec_equiv p1 p2 c12 c12'
))
(ensures (
exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')
))
[SMTPatOr [
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p0 p1 c01 c01')];
[SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')); SMTPat (exec_equiv p1 p2 c12 c12')];
[SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')];
]]
= d_seq (interp p0) (interp p1) (interp p2) c01 c01' c12 c12'
let r_ass
(x y: var)
(e e' : exp int)
(p: gexp bool)
: Lemma
(exec_equiv
(gsubst (gsubst p x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
p
(assign x e)
(assign y e')
)
= ()
let included_alt (p1 p2 : gexp bool) : Lemma
(included p1 p2 <==> (forall s1 s2 . p1 s1 s2 == true ==> p2 s1 s2 == true))
[SMTPat (included p1 p2)]
= assert (forall s1 s2 . holds (interp p1) s1 s2 <==> p1 s1 s2 == true);
assert (forall s1 s2 . holds (interp p2) s1 s2 <==> p2 s1 s2 == true)
let r_sub
(p1 p2 p1' p2' : gexp bool)
(f f' : computation)
: Lemma
(requires (
exec_equiv p1 p2 f f' /\
included p1' p1 /\
included p2 p2'
))
(ensures (exec_equiv p1' p2' f f'))
[SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')]
= d_csub (interp p1) (interp p2) (interp p1') (interp p2') f f'
let elim_fuel_monotonic (fc:reified_computation) (s0:heap) (f0 f1:nat)
: Lemma (requires f0 <= f1 /\ fst (fc f0 s0))
(ensures fc f0 s0 == fc f1 s0)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"Benton2004.fst.checked"
],
"interface_file": true,
"source_file": "Benton2004.RHL.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Benton2004.exp Prims.bool ->
b': Benton2004.exp Prims.bool ->
c: Benton2004.computation ->
c': Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi_c: Benton2004.RHL.gexp Prims.bool ->
phi_c': Benton2004.RHL.gexp Prims.bool ->
s0: FStar.DM4F.Heap.IntStoreFixed.heap ->
s0': FStar.DM4F.Heap.IntStoreFixed.heap ->
fuel: Prims.nat
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.included phi
(Benton2004.RHL.geq (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)) /\
Benton2004.RHL.included (Benton2004.RHL.gand phi
(Benton2004.RHL.gand (Benton2004.RHL.exp_to_gexp b Benton2004.RHL.Left)
(Benton2004.RHL.exp_to_gexp b' Benton2004.RHL.Right)))
phi_c /\ Benton2004.RHL.included phi_c' phi /\ Benton2004.RHL.exec_equiv phi_c phi_c' c c' /\
Benton2004.Aux.holds (Benton2004.RHL.interp phi) s0 s0' /\
FStar.Pervasives.Native.fst (Benton2004.reify_computation (Benton2004.while b c) fuel s0) ==
true)
(ensures Benton2004.terminates_on (Benton2004.reify_computation (Benton2004.while b' c')) s0')
(decreases fuel) | FStar.Pervasives.Lemma | [
"",
"lemma"
] | [] | [
"Benton2004.exp",
"Prims.bool",
"Benton2004.computation",
"Benton2004.RHL.gexp",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"Prims.nat",
"FStar.Pervasives.Native.fst",
"Benton2004.reify_exp",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Prims.eq2",
"Benton2004.terminates_on",
"FStar.Classical.move_requires",
"Prims.unit",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims._assert",
"FStar.Pervasives.Native.tuple2",
"Benton2004.reified_computation_elim",
"Prims.op_Subtraction",
"Prims.int",
"Prims.op_Addition",
"Benton2004.RHL.r_while_terminates'",
"Benton2004.RHL.elim_fuel_monotonic",
"Benton2004.Aux.holds",
"Benton2004.RHL.interp",
"Benton2004.terminates_equiv_reified",
"Prims.b2t",
"FStar.Pervasives.Native.snd",
"Benton2004.RHL.gand",
"Benton2004.RHL.exp_to_gexp",
"Benton2004.RHL.Left",
"Benton2004.RHL.Right",
"Benton2004.reified_computation",
"Benton2004.reify_computation",
"Benton2004.while",
"Prims.l_and",
"Benton2004.RHL.included",
"Benton2004.RHL.geq",
"Benton2004.RHL.exec_equiv"
] | [
"recursion"
] | false | false | true | false | false | let rec r_while_terminates'
(b b': exp bool)
(c c': computation)
(phi phi_c phi_c': gexp bool)
(s0 s0': heap)
(fuel: nat)
: Lemma
(requires
(included phi (geq (exp_to_gexp b Left) (exp_to_gexp b' Right)) /\
included (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right))) phi_c /\
included phi_c' phi /\ exec_equiv phi_c phi_c' c c' /\ holds (interp phi) s0 s0' /\
fst (reify_computation (while b c) fuel s0) == true))
(ensures (terminates_on (reify_computation (while b' c')) s0'))
(decreases fuel) =
| let f = reify_computation (while b c) in
let f' = reify_computation (while b' c') in
let fc = reify_computation c in
let fc' = reify_computation c' in
if fst (reify_exp b s0)
then
(assert (holds (interp (gand phi (gand (exp_to_gexp b Left) (exp_to_gexp b' Right)))) s0 s0');
assert (terminates_on (fc') s0');
let g (fuel0: nat)
: Lemma (requires (fst (fc' fuel0 s0') == true)) (ensures (terminates_on (f') s0')) =
let s1 = snd (fc fuel s0) in
let s1' = snd (fc' fuel0 s0') in
let fuel1 = fuel + fuel0 in
assert (fst (fc' fuel0 s0'));
assert (terminates_equiv_reified (interp phi_c) fc fc');
assert (holds (interp phi_c) s0 s0');
assert (terminates_on fc s0);
elim_fuel_monotonic fc s0 fuel fuel1;
elim_fuel_monotonic fc' s0' fuel0 fuel1;
assert (fc fuel1 s0 == fc fuel s0);
assert (fc' fuel1 s0' == fc' fuel0 s0');
r_while_terminates' b b' c c' phi phi_c phi_c' s1 s1' (fuel - 1);
let g' (fuel2: nat)
: Lemma (requires (fst (f' fuel2 s1') == true)) (ensures (terminates_on (f') s0')) =
let fuel3 = fuel0 + fuel2 + 1 in
assert (f' (fuel3 - 1) s1' == f' fuel2 s1');
reified_computation_elim fc' fuel0 fuel3 s0';
assert (fc' fuel3 s0' == fc' fuel0 s0');
assert (fst (f' fuel3 s0') == true)
in
Classical.forall_intro (Classical.move_requires g')
in
Classical.forall_intro (Classical.move_requires g)) | false |
Spec.P256.fst | Spec.P256.point_mul_g | val point_mul_g (a: qelem) : proj_point | val point_mul_g (a: qelem) : proj_point | let point_mul_g (a:qelem) : proj_point = point_mul a base_point | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 63,
"start_col": 0,
"start_line": 63
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4 | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.proj_point | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.PointOps.qelem",
"Spec.P256.point_mul",
"Spec.P256.PointOps.base_point",
"Spec.P256.PointOps.proj_point"
] | [] | false | false | false | true | false | let point_mul_g (a: qelem) : proj_point =
| point_mul a base_point | false |
Spec.P256.fst | Spec.P256.mk_p256_comm_monoid | val mk_p256_comm_monoid:LE.comm_monoid aff_point | val mk_p256_comm_monoid:LE.comm_monoid aff_point | let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
} | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 1,
"end_line": 28,
"start_col": 0,
"start_line": 22
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Lib.Exponentiation.Definition.comm_monoid Spec.P256.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.Mkcomm_monoid",
"Spec.P256.PointOps.aff_point",
"Spec.P256.PointOps.aff_point_at_inf",
"Spec.P256.PointOps.aff_point_add",
"Spec.P256.Lemmas.aff_point_at_inf_lemma",
"Spec.P256.Lemmas.aff_point_add_assoc_lemma",
"Spec.P256.Lemmas.aff_point_add_comm_lemma"
] | [] | false | false | false | true | false | let mk_p256_comm_monoid:LE.comm_monoid aff_point =
| {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma
} | false |
Spec.P256.fst | Spec.P256.point_double_c | val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid | val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid | let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 49,
"start_col": 0,
"start_line": 47
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Spec.Exponentiation.sqr_st Spec.P256.PointOps.proj_point Spec.P256.mk_to_p256_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.PointOps.proj_point",
"Spec.P256.PointOps.point_double",
"Prims.unit",
"Spec.P256.Lemmas.to_aff_point_double_lemma"
] | [] | false | false | false | true | false | let point_double_c p =
| PL.to_aff_point_double_lemma p;
point_double p | false |
Spec.P256.fst | Spec.P256.point_mul | val point_mul (a: qelem) (p: proj_point) : proj_point | val point_mul (a: qelem) (p: proj_point) : proj_point | let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4 | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 60,
"start_col": 0,
"start_line": 59
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
} | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.P256.PointOps.qelem -> p: Spec.P256.PointOps.proj_point -> Spec.P256.PointOps.proj_point | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.PointOps.qelem",
"Spec.P256.PointOps.proj_point",
"Spec.Exponentiation.exp_fw",
"Spec.P256.mk_p256_concrete_ops"
] | [] | false | false | false | true | false | let point_mul (a: qelem) (p: proj_point) : proj_point =
| SE.exp_fw mk_p256_concrete_ops p 256 a 4 | false |
Spec.P256.fst | Spec.P256.point_add_c | val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid | val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid | let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 44,
"start_col": 0,
"start_line": 42
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Spec.Exponentiation.mul_st Spec.P256.PointOps.proj_point Spec.P256.mk_to_p256_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.PointOps.proj_point",
"Spec.P256.PointOps.point_add",
"Prims.unit",
"Spec.P256.Lemmas.to_aff_point_add_lemma"
] | [] | false | false | false | true | false | let point_add_c p q =
| PL.to_aff_point_add_lemma p q;
point_add p q | false |
Spec.P256.fst | Spec.P256.point_mul_double_g | val point_mul_double_g (a1 a2: qelem) (p: proj_point) : proj_point | val point_mul_double_g (a1 a2: qelem) (p: proj_point) : proj_point | let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 67,
"start_col": 0,
"start_line": 66
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | a1: Spec.P256.PointOps.qelem -> a2: Spec.P256.PointOps.qelem -> p: Spec.P256.PointOps.proj_point
-> Spec.P256.PointOps.proj_point | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.PointOps.qelem",
"Spec.P256.PointOps.proj_point",
"Spec.Exponentiation.exp_double_fw",
"Spec.P256.mk_p256_concrete_ops",
"Spec.P256.PointOps.base_point"
] | [] | false | false | false | true | false | let point_mul_double_g (a1 a2: qelem) (p: proj_point) : proj_point =
| SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 | false |
Spec.P256.fst | Spec.P256.point_at_inf_c | val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid | val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid | let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 39,
"start_col": 0,
"start_line": 37
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
} | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Spec.Exponentiation.one_st Spec.P256.PointOps.proj_point Spec.P256.mk_to_p256_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Spec.P256.PointOps.point_at_inf",
"Spec.P256.Lemmas.to_aff_point_at_infinity_lemma",
"Spec.P256.PointOps.proj_point"
] | [] | false | false | false | true | false | let point_at_inf_c _ =
| PL.to_aff_point_at_infinity_lemma ();
point_at_inf | false |
Spec.P256.fst | Spec.P256.min_input_length | val min_input_length (a: hash_alg_ecdsa) : nat | val min_input_length (a: hash_alg_ecdsa) : nat | let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0 | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 84,
"start_col": 0,
"start_line": 83
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32 | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.P256.hash_alg_ecdsa -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.hash_alg_ecdsa",
"Spec.Hash.Definitions.hash_alg",
"Prims.l_or",
"Prims.eq2",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Hash.Definitions.SHA2_384",
"Spec.Hash.Definitions.SHA2_512",
"Prims.nat"
] | [] | false | false | false | true | false | let min_input_length (a: hash_alg_ecdsa) : nat =
| match a with
| NoHash -> 32
| Hash a -> 0 | false |
Spec.P256.fst | Spec.P256.hash_ecdsa | val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) | val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) | let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 95,
"start_col": 0,
"start_line": 94
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.P256.hash_alg_ecdsa ->
msg_len: Lib.IntTypes.size_nat{msg_len >= Spec.P256.min_input_length a} ->
msg: Lib.Sequence.lseq Lib.IntTypes.uint8 msg_len
-> r:
Lib.ByteSequence.lbytes (match Hash? a with
| true ->
Spec.Hash.Definitions.hash_length (let Spec.P256.Hash a = a in
a)
| _ -> msg_len) {Lib.Sequence.length r >= 32} | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.hash_alg_ecdsa",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Spec.P256.min_input_length",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.hash_alg",
"Prims.l_or",
"Prims.eq2",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Hash.Definitions.SHA2_384",
"Spec.Hash.Definitions.SHA2_512",
"Spec.Agile.Hash.hash",
"Lib.ByteSequence.lbytes",
"Spec.P256.uu___is_Hash",
"Spec.Hash.Definitions.hash_length",
"Prims.op_Negation",
"Spec.Hash.Definitions.is_shake",
"Prims.bool",
"Lib.Sequence.length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC"
] | [] | false | false | false | false | false | let hash_ecdsa a msg_len msg =
| match a with
| NoHash -> msg
| Hash a -> Spec.Agile.Hash.hash a msg | false |
Spec.P256.fst | Spec.P256.ecdsa_verify_msg_as_qelem | val ecdsa_verify_msg_as_qelem (m: qelem) (public_key: lbytes 64) (sign_r sign_s: lbytes 32) : bool | val ecdsa_verify_msg_as_qelem (m: qelem) (public_key: lbytes 64) (sign_r sign_s: lbytes 32) : bool | let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 134,
"start_col": 0,
"start_line": 117
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: Spec.P256.PointOps.qelem ->
public_key: Lib.ByteSequence.lbytes 64 ->
sign_r: Lib.ByteSequence.lbytes 32 ->
sign_s: Lib.ByteSequence.lbytes 32
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.PointOps.qelem",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.op_AmpAmp",
"FStar.Pervasives.Native.uu___is_Some",
"Spec.P256.PointOps.proj_point",
"Prims.bool",
"Prims.nat",
"Spec.P256.PointOps.is_point_at_inf",
"FStar.Pervasives.Native.Mktuple3",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Spec.P256.PointOps.order",
"Spec.P256.PointOps.felem",
"Spec.P256.PointOps.op_Slash_Percent",
"Spec.P256.point_mul_double_g",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Spec.P256.PointOps.op_Star_Hat",
"Spec.P256.PointOps.qinv",
"Prims.op_LessThan",
"Prims.b2t",
"Prims.pow2",
"Prims.op_Multiply",
"Lib.Sequence.length",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.ByteSequence.nat_from_bytes_be",
"FStar.Pervasives.Native.option",
"Spec.P256.PointOps.load_point"
] | [] | false | false | false | false | false | let ecdsa_verify_msg_as_qelem (m: qelem) (public_key: lbytes 64) (sign_r sign_s: lbytes 32) : bool =
| let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid)
then false
else
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z)
then false
else
let x = _X /% _Z in
x % order = r | false |
Spec.P256.fst | Spec.P256.ecdsa_sign_msg_as_qelem | val ecdsa_sign_msg_as_qelem (m: qelem) (private_key nonce: lbytes 32) : option (lbytes 64) | val ecdsa_sign_msg_as_qelem (m: qelem) (private_key nonce: lbytes 32) : option (lbytes 64) | let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 114,
"start_col": 0,
"start_line": 98
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: Spec.P256.PointOps.qelem ->
private_key: Lib.ByteSequence.lbytes 32 ->
nonce: Lib.ByteSequence.lbytes 32
-> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64) | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.PointOps.qelem",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.op_AmpAmp",
"FStar.Pervasives.Native.None",
"Prims.bool",
"Prims.nat",
"Prims.op_BarBar",
"Prims.op_Equality",
"Prims.int",
"FStar.Pervasives.Native.Some",
"Lib.Sequence.concat",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.option",
"Lib.Sequence.seq",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.length",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Multiply",
"Lib.ByteSequence.nat_from_intseq_be",
"Lib.ByteSequence.nat_to_bytes_be",
"Spec.P256.PointOps.op_Star_Hat",
"Spec.P256.PointOps.op_Plus_Hat",
"Spec.P256.PointOps.qinv",
"Prims.op_Modulus",
"Spec.P256.PointOps.order",
"Spec.P256.PointOps.felem",
"Spec.P256.PointOps.op_Slash_Percent",
"Spec.P256.PointOps.proj_point",
"Spec.P256.point_mul_g",
"Lib.ByteSequence.nat_from_bytes_be"
] | [] | false | false | false | false | false | let ecdsa_sign_msg_as_qelem (m: qelem) (private_key nonce: lbytes 32) : option (lbytes 64) =
| let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid)
then None
else
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) | false |
Spec.P256.fst | Spec.P256.validate_public_key | val validate_public_key (pk: lbytes 64) : bool | val validate_public_key (pk: lbytes 64) : bool | let validate_public_key (pk:lbytes 64) : bool =
Some? (load_point pk) | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 202,
"start_col": 0,
"start_line": 201
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
/// ECDH over the P256 elliptic curve
let secret_to_public (private_key:lbytes 32) : option (lbytes 64) =
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid then
let pk = point_mul_g sk in
Some (point_store pk)
else None
let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) =
let pk = load_point their_public_key in
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if Some? pk && is_sk_valid then
let ss = point_mul sk (Some?.v pk) in
Some (point_store ss)
else None
/// Parsing and Serializing public keys
// raw = [ x; y ], 64 bytes
// uncompressed = [ 0x04; x; y ], 65 bytes
// compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | pk: Lib.ByteSequence.lbytes 64 -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Lib.ByteSequence.lbytes",
"FStar.Pervasives.Native.uu___is_Some",
"Spec.P256.PointOps.proj_point",
"Spec.P256.PointOps.load_point",
"Prims.bool"
] | [] | false | false | false | false | false | let validate_public_key (pk: lbytes 64) : bool =
| Some? (load_point pk) | false |
Spec.P256.fst | Spec.P256.ecdsa_verification_agile | val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool | val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool | let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 171,
"start_col": 0,
"start_line": 168
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
alg: Spec.P256.hash_alg_ecdsa ->
msg_len: Lib.IntTypes.size_nat{msg_len >= Spec.P256.min_input_length alg} ->
msg: Lib.ByteSequence.lbytes msg_len ->
public_key: Lib.ByteSequence.lbytes 64 ->
signature_r: Lib.ByteSequence.lbytes 32 ->
signature_s: Lib.ByteSequence.lbytes 32
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.hash_alg_ecdsa",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Spec.P256.min_input_length",
"Lib.ByteSequence.lbytes",
"Spec.P256.ecdsa_verify_msg_as_qelem",
"Prims.int",
"Prims.op_Modulus",
"Lib.ByteSequence.nat_from_bytes_be",
"Lib.IntTypes.SEC",
"Lib.Sequence.sub",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Spec.P256.uu___is_Hash",
"Spec.Hash.Definitions.hash_length",
"Spec.Hash.Definitions.hash_alg",
"Prims.l_or",
"Prims.eq2",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Hash.Definitions.SHA2_384",
"Spec.Hash.Definitions.SHA2_512",
"Prims.op_Negation",
"Spec.Hash.Definitions.is_shake",
"Prims.bool",
"Spec.P256.PointOps.order",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.Sequence.length",
"Spec.P256.hash_ecdsa"
] | [] | false | false | false | false | false | let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
| let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s | false |
Spec.P256.fst | Spec.P256.pk_uncompressed_to_raw | val pk_uncompressed_to_raw (pk: lbytes 65) : option (lbytes 64) | val pk_uncompressed_to_raw (pk: lbytes 65) : option (lbytes 64) | let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) =
if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64) | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 205,
"start_col": 0,
"start_line": 204
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
/// ECDH over the P256 elliptic curve
let secret_to_public (private_key:lbytes 32) : option (lbytes 64) =
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid then
let pk = point_mul_g sk in
Some (point_store pk)
else None
let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) =
let pk = load_point their_public_key in
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if Some? pk && is_sk_valid then
let ss = point_mul sk (Some?.v pk) in
Some (point_store ss)
else None
/// Parsing and Serializing public keys
// raw = [ x; y ], 64 bytes
// uncompressed = [ 0x04; x; y ], 65 bytes
// compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes
let validate_public_key (pk:lbytes 64) : bool =
Some? (load_point pk) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | pk: Lib.ByteSequence.lbytes 65 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64) | Prims.Tot | [
"total"
] | [] | [
"Lib.ByteSequence.lbytes",
"Prims.op_disEquality",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_to_UInt8",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt8.__uint_to_t",
"FStar.Pervasives.Native.None",
"Prims.bool",
"FStar.Pervasives.Native.Some",
"Lib.Sequence.sub",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | false | let pk_uncompressed_to_raw (pk: lbytes 65) : option (lbytes 64) =
| if Lib.RawIntTypes.u8_to_UInt8 pk.[ 0 ] <> 0x04uy then None else Some (sub pk 1 64) | false |
Spec.P256.fst | Spec.P256.ecdh | val ecdh (their_public_key: lbytes 64) (private_key: lbytes 32) : option (lbytes 64) | val ecdh (their_public_key: lbytes 64) (private_key: lbytes 32) : option (lbytes 64) | let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) =
let pk = load_point their_public_key in
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if Some? pk && is_sk_valid then
let ss = point_mul sk (Some?.v pk) in
Some (point_store ss)
else None | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 192,
"start_col": 0,
"start_line": 185
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
/// ECDH over the P256 elliptic curve
let secret_to_public (private_key:lbytes 32) : option (lbytes 64) =
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid then
let pk = point_mul_g sk in
Some (point_store pk)
else None | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | their_public_key: Lib.ByteSequence.lbytes 64 -> private_key: Lib.ByteSequence.lbytes 32
-> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64) | Prims.Tot | [
"total"
] | [] | [
"Lib.ByteSequence.lbytes",
"Prims.op_AmpAmp",
"FStar.Pervasives.Native.uu___is_Some",
"Spec.P256.PointOps.proj_point",
"FStar.Pervasives.Native.Some",
"Spec.P256.PointOps.point_store",
"Spec.P256.point_mul",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"Prims.op_LessThan",
"Spec.P256.PointOps.order",
"Prims.nat",
"Prims.b2t",
"Prims.pow2",
"Prims.op_Multiply",
"Lib.Sequence.length",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.ByteSequence.nat_from_bytes_be",
"Spec.P256.PointOps.load_point"
] | [] | false | false | false | false | false | let ecdh (their_public_key: lbytes 64) (private_key: lbytes 32) : option (lbytes 64) =
| let pk = load_point their_public_key in
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if Some? pk && is_sk_valid
then
let ss = point_mul sk (Some?.v pk) in
Some (point_store ss)
else None | false |
Spec.P256.fst | Spec.P256.ecdsa_signature_agile | val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64) | val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64) | let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 156,
"start_col": 0,
"start_line": 153
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
alg: Spec.P256.hash_alg_ecdsa ->
msg_len: Lib.IntTypes.size_nat{msg_len >= Spec.P256.min_input_length alg} ->
msg: Lib.ByteSequence.lbytes msg_len ->
private_key: Lib.ByteSequence.lbytes 32 ->
nonce: Lib.ByteSequence.lbytes 32
-> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64) | Prims.Tot | [
"total"
] | [] | [
"Spec.P256.hash_alg_ecdsa",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Spec.P256.min_input_length",
"Lib.ByteSequence.lbytes",
"Spec.P256.ecdsa_sign_msg_as_qelem",
"Prims.int",
"Prims.op_Modulus",
"Lib.ByteSequence.nat_from_bytes_be",
"Lib.IntTypes.SEC",
"Lib.Sequence.sub",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Spec.P256.uu___is_Hash",
"Spec.Hash.Definitions.hash_length",
"Spec.Hash.Definitions.hash_alg",
"Prims.l_or",
"Prims.eq2",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Hash.Definitions.SHA2_384",
"Spec.Hash.Definitions.SHA2_512",
"Prims.op_Negation",
"Spec.Hash.Definitions.is_shake",
"Prims.bool",
"Spec.P256.PointOps.order",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.Sequence.length",
"Spec.P256.hash_ecdsa",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | false | let ecdsa_signature_agile alg msg_len msg private_key nonce =
| let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce | false |
Spec.P256.fst | Spec.P256.pk_uncompressed_from_raw | val pk_uncompressed_from_raw (pk: lbytes 64) : lbytes 65 | val pk_uncompressed_from_raw (pk: lbytes 64) : lbytes 65 | let pk_uncompressed_from_raw (pk:lbytes 64) : lbytes 65 =
concat (create 1 (u8 0x04)) pk | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 208,
"start_col": 0,
"start_line": 207
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
/// ECDH over the P256 elliptic curve
let secret_to_public (private_key:lbytes 32) : option (lbytes 64) =
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid then
let pk = point_mul_g sk in
Some (point_store pk)
else None
let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) =
let pk = load_point their_public_key in
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if Some? pk && is_sk_valid then
let ss = point_mul sk (Some?.v pk) in
Some (point_store ss)
else None
/// Parsing and Serializing public keys
// raw = [ x; y ], 64 bytes
// uncompressed = [ 0x04; x; y ], 65 bytes
// compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes
let validate_public_key (pk:lbytes 64) : bool =
Some? (load_point pk)
let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) =
if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | pk: Lib.ByteSequence.lbytes 64 -> Lib.ByteSequence.lbytes 65 | Prims.Tot | [
"total"
] | [] | [
"Lib.ByteSequence.lbytes",
"Lib.Sequence.concat",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.create",
"Lib.IntTypes.u8"
] | [] | false | false | false | false | false | let pk_uncompressed_from_raw (pk: lbytes 64) : lbytes 65 =
| concat (create 1 (u8 0x04)) pk | false |
Spec.P256.fst | Spec.P256.secret_to_public | val secret_to_public (private_key: lbytes 32) : option (lbytes 64) | val secret_to_public (private_key: lbytes 32) : option (lbytes 64) | let secret_to_public (private_key:lbytes 32) : option (lbytes 64) =
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid then
let pk = point_mul_g sk in
Some (point_store pk)
else None | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 182,
"start_col": 0,
"start_line": 176
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
/// ECDH over the P256 elliptic curve | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | private_key: Lib.ByteSequence.lbytes 32
-> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64) | Prims.Tot | [
"total"
] | [] | [
"Lib.ByteSequence.lbytes",
"FStar.Pervasives.Native.Some",
"Spec.P256.PointOps.point_store",
"Spec.P256.PointOps.proj_point",
"Spec.P256.point_mul_g",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Spec.P256.PointOps.order",
"Prims.nat",
"Prims.b2t",
"Prims.pow2",
"Prims.op_Multiply",
"Lib.Sequence.length",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.ByteSequence.nat_from_bytes_be"
] | [] | false | false | false | false | false | let secret_to_public (private_key: lbytes 32) : option (lbytes 64) =
| let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid
then
let pk = point_mul_g sk in
Some (point_store pk)
else None | false |
Spec.P256.fst | Spec.P256.pk_compressed_to_raw | val pk_compressed_to_raw (pk: lbytes 33) : option (lbytes 64) | val pk_compressed_to_raw (pk: lbytes 33) : option (lbytes 64) | let pk_compressed_to_raw (pk:lbytes 33) : option (lbytes 64) =
let pk_x = sub pk 1 32 in
match (aff_point_decompress pk) with
| Some (x, y) -> Some (concat #_ #32 #32 pk_x (nat_to_bytes_be 32 y))
| None -> None | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 214,
"start_col": 0,
"start_line": 210
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
/// ECDH over the P256 elliptic curve
let secret_to_public (private_key:lbytes 32) : option (lbytes 64) =
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid then
let pk = point_mul_g sk in
Some (point_store pk)
else None
let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) =
let pk = load_point their_public_key in
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if Some? pk && is_sk_valid then
let ss = point_mul sk (Some?.v pk) in
Some (point_store ss)
else None
/// Parsing and Serializing public keys
// raw = [ x; y ], 64 bytes
// uncompressed = [ 0x04; x; y ], 65 bytes
// compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes
let validate_public_key (pk:lbytes 64) : bool =
Some? (load_point pk)
let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) =
if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64)
let pk_uncompressed_from_raw (pk:lbytes 64) : lbytes 65 =
concat (create 1 (u8 0x04)) pk | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | pk: Lib.ByteSequence.lbytes 33 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64) | Prims.Tot | [
"total"
] | [] | [
"Lib.ByteSequence.lbytes",
"Spec.P256.PointOps.aff_point_decompress",
"Prims.nat",
"FStar.Pervasives.Native.Some",
"Lib.Sequence.concat",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.ByteSequence.nat_to_bytes_be",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub"
] | [] | false | false | false | false | false | let pk_compressed_to_raw (pk: lbytes 33) : option (lbytes 64) =
| let pk_x = sub pk 1 32 in
match (aff_point_decompress pk) with
| Some (x, y) -> Some (concat #_ #32 #32 pk_x (nat_to_bytes_be 32 y))
| None -> None | false |
MiniValeSemantics.fst | MiniValeSemantics.inst_Triple | val inst_Triple:with_wps codes_Triple | val inst_Triple:with_wps codes_Triple | let inst_Triple : with_wps codes_Triple = //A typeclass instance for our program
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (
QSeq (inst_Add (OReg Rax) (OReg Rbx)) (
QSeq (inst_Add (OReg Rbx) (OReg Rax)) (
QEmpty))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) | {
"file_name": "examples/metatheory/MiniValeSemantics.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 68,
"end_line": 945,
"start_col": 0,
"start_line": 675
} | (*
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.
Authors: C. Hawblitzel, N. Swamy
*)
module MiniValeSemantics
(*
This is a highly-simplified model of Vale/F*, based on Section
3.1-3.3 of the paper of the POPL '19 paper.
It is derived from the QuickRegs1 code in the popl-artifact-submit
branch of Vale.
*)
/// We use this tag to mark certain definitions
/// and control normalization based on it
irreducible
let qattr = ()
/// 2^64
let pow2_64 = 0x10000000000000000
/// Natural numbers representable in 64 bits
type nat64 = i:int{0 <= i /\ i < pow2_64}
/// We have 4 registers
type reg = | Rax | Rbx | Rcx | Rdx
/// An operand is either a register or a constant
type operand =
| OReg: r:reg -> operand
| OConst: n:nat64 -> operand
/// Only 2 instructions here:
/// A move or an add
type ins =
| Mov64: dst:operand -> src:operand -> ins
| Add64: dst:operand -> src:operand -> ins
/// A program is
/// - a single instruction
/// - a block of instructions
/// - or a while loop
type code =
| Ins: ins:ins -> code
| Block: block:list code -> code
| WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code
/// The state of a program is the register file
/// holiding a 64-bit value for each register
type state = reg -> nat64
/// fuel: To prove the termination of while loops, we're going to
/// instrument while loops with fuel
type fuel = nat
/// Evaluating an operand:
/// -- marked for reduction
/// -- Registers evaluated by state lookup
[@@qattr]
let eval_operand (o:operand) (s:state) : nat64 =
match o with
| OReg r -> s r
| OConst n -> n
/// updating a register state `s` at `r` with `v`
[@@qattr]
let update_reg (s:state) (r:reg) (v:nat64) : state =
fun r' -> if r = r' then v else s r'
/// updating a register state `s` at `r` with `s' r`
[@@qattr]
let update_state (r:reg) (s' s:state) : state =
update_reg s r (s' r)
// We don't have an "ok" flag, so errors just result an arbitrary state:
assume
val unknown_state (s:state) : state
(*** A basic semantics using
a big-step interpreter
***)
/// Instruction evaluation:
/// only some operands are valid
let eval_ins (ins:ins) (s:state) : state =
match ins with
| Mov64 (OConst _) _ ->
unknown_state s
| Mov64 (OReg dst) src ->
update_reg s dst (eval_operand src s)
| Add64 (OConst _) _ ->
unknown_state s
| Add64 (OReg dst) src ->
update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000)
/// eval_code:
/// A fueled big-step interpreter
/// While lops return None when we're out of fuel
let rec eval_code (c:code) (f:fuel) (s:state) : option state =
match c with
| Ins ins ->
Some (eval_ins ins s)
| Block cs ->
eval_codes cs f s
| WhileLessThan src1 src2 body ->
if f = 0 then None
else if eval_operand src1 s < eval_operand src2 s then
match eval_code body f s with
| None -> None
| Some s -> eval_code c (f - 1) s
else Some s
and eval_codes (cs:list code) (f:fuel) (s:state) : option state =
match cs with
| [] -> Some s
| c::cs ->
match eval_code c f s with
| None -> None
| Some s -> eval_codes cs f s
(*** END OF TRUSTED SEMANTICS ***)
////////////////////////////////////////////////////////////////////////////////
/// 1. We prove that increasing the fuel is irrelevant to terminating executions
val increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma
(requires
eval_code c f0 s0 == Some sN /\
f0 <= fN)
(ensures
eval_code c fN s0 == Some sN)
(decreases %[f0; c])
val increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma
(requires
eval_code (Block c) f0 s0 == Some sN /\
f0 <= fN)
(ensures
eval_code (Block c) fN s0 == Some sN)
(decreases %[f0; c])
let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) =
match c with
| Ins ins -> ()
| Block l -> increase_fuels l s0 f0 sN fN
| WhileLessThan src1 src2 body ->
if eval_operand src1 s0 < eval_operand src2 s0 then
match eval_code body f0 s0 with
| None -> ()
| Some s1 ->
increase_fuel body s0 f0 s1 fN;
increase_fuel c s1 (f0 - 1) sN (fN - 1)
else ()
and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) =
match c with
| [] -> ()
| h::t ->
let Some s1 = eval_code h f0 s0 in
increase_fuel h s0 f0 s1 fN;
increase_fuels t s1 f0 sN fN
/// 2. We can compute the fuel needed to run a sequential composition
/// as the max of the fuel to compute each piece of code in it
let lemma_merge (c:code) (cs:list code) (s0:state) (f0:fuel) (sM:state) (fM:fuel) (sN:state)
: Ghost fuel
(requires
eval_code c f0 s0 == Some sM /\
eval_code (Block cs) fM sM == Some sN)
(ensures fun fN ->
eval_code (Block (c::cs)) fN s0 == Some sN)
=
let f = if f0 > fM then f0 else fM in
increase_fuel c s0 f0 sM f;
increase_fuel (Block cs) sM fM sN f;
f
/////////////////////////////////////////////////////////////////
// Now, we're going to define a verification-condition generator
//
// The main idea is that we're going to:
//
// 1. define a kind of typeclass, that associates with a
// piece of code a weakest-precondition rule for it
//
// 2. Define a WP-generator that computes WPs for each of the
// control constructs of the language, given a program
// represented as the raw code packaged with their typeclass
// instances for computing their WPs
/////////////////////////////////////////////////////////////////
[@@qattr]
let t_post = state -> Type0
[@@qattr]
let t_pre = state -> Type0
/// t_wp: The type of weakest preconditions
let t_wp = t_post -> t_pre
/// c `has_wp` wp: The main judgment in our program logic
let has_wp (c:code) (wp:t_wp) : Type =
k:t_post -> //for any post-condition
s0:state -> //and initial state
Ghost (state * fuel)
(requires wp k s0) //Given the precondition
(ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that
eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM
k sM) //and the post-condition is true on sM
/// An abbreviation for a thunked lemma
let t_lemma (pre:Type0) (post:Type0) =
unit -> Lemma (requires pre) (ensures post)
/// `with_wp` : A typeclass for code packaged with its wp
[@@qattr]
noeq
type with_wp : code -> Type =
| QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c
/// `with_wps`: A typclass for lists of code values packages with their wps
noeq
type with_wps : list code -> Type =
| QEmpty: //empty list
with_wps []
| QSeq: //cons
#c:code ->
#cs:list code ->
hd:with_wp c ->
tl:with_wps cs ->
with_wps (c::cs)
| QLemma: //augmenting an instruction sequence with a lemma
#cs:list code ->
pre:Type0 ->
post:Type0 ->
t_lemma pre post ->
with_wps cs ->
with_wps cs
[@@qattr]
let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post)
: Tot (state -> Tot Type0 (decreases qcs))
=
fun s0 ->
match qcs with
| QEmpty ->
k s0 //no instructions; prove the postcondition right away
| QSeq qc qcs ->
// let pre_tl = //compute the VC generator for the tail, a precondition
qc.wp (vc_gen (Cons?.tl cs) qcs k) s0
// in
// qc.wp pre_tl s0 //apply the wp-generator to the precondition for the tail
| QLemma pre post _ qcs ->
pre /\ //prove the precondition of the lemma
(post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the program
/// The vc-generator is sound
let rec vc_sound (cs:list code)
(qcs:with_wps cs)
(k:state -> Type0)
(s0:state)
: Ghost (state * fuel)
(requires vc_gen cs qcs k s0)
(ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN)
= match qcs with
| QEmpty -> (s0, 0)
| QSeq qc qcs ->
let Cons c cs' = cs in
let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in
let (sN, fN) = vc_sound cs' qcs k sM in
let fN' = lemma_merge c cs' s0 fM sM fN sN in
(sN, fN')
| QLemma pre post lem qcs' ->
lem ();
vc_sound cs qcs' k s0
let vc_sound' (cs:list code) (qcs:with_wps cs)
: has_wp (Block cs) (vc_gen cs qcs)
= vc_sound cs qcs
(*** Instances of with_wp ***)
////////////////////////////////////////////////////////////////////////////////
//Instance for Mov
////////////////////////////////////////////////////////////////////////////////
let lemma_Move (s0:state) (dst:operand) (src:operand)
: Ghost (state * fuel)
(requires OReg? dst)
(ensures fun (sM, fM) ->
eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\
eval_operand dst sM == eval_operand src s0 /\
sM == update_state (OReg?.r dst) sM s0
)
=
let Some sM = eval_code (Ins (Mov64 dst src)) 0 s0 in
(sM, 0)
[@@qattr]
let wp_Move (dst:operand) (src:operand) (k:state -> Type0) (s0:state) : Type0 =
OReg? dst /\
(forall (x:nat64).
let sM = update_reg s0 (OReg?.r dst) x in
eval_operand dst sM == eval_operand src s0 ==> k sM
)
let hasWp_Move (dst:operand) (src:operand) (k:state -> Type0) (s0:state) : Ghost (state * fuel)
(requires wp_Move dst src k s0)
(ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM)
=
lemma_Move s0 dst src
[@@qattr]
let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) =
QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src)
////////////////////////////////////////////////////////////////////////////////
//Instance for Add
////////////////////////////////////////////////////////////////////////////////
let lemma_Add (s0:state) (dst:operand) (src:operand) : Ghost (state * fuel)
(requires OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64)
(ensures fun (sM, fM) ->
eval_code (Ins (Add64 dst src)) fM s0 == Some sM /\
eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 /\
sM == update_state (OReg?.r dst) sM s0
)
=
let Some sM = eval_code (Ins (Add64 dst src)) 0 s0 in
(sM, 0)
[@@qattr]
let wp_Add (dst:operand) (src:operand) (k:state -> Type0) (s0:state) : Type0 =
OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\
(forall (x:nat64).
let sM = update_reg s0 (OReg?.r dst) x in
eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM
)
let hasWp_Add (dst:operand) (src:operand) (k:state -> Type0) (s0:state) : Ghost (state * fuel)
(requires wp_Add dst src k s0)
(ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM)
=
lemma_Add s0 dst src
[@@qattr]
let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) =
QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src)
////////////////////////////////////////////////////////////////////////////////
//Running the VC generator using the F* normalizer
////////////////////////////////////////////////////////////////////////////////
unfold
let normal_steps : list string =
[
`%OReg?;
`%OReg?.r;
`%QProc?.wp;
]
unfold
let normal (x:Type0) : Type0 =
norm [nbe; iota; zeta; simplify; primops; delta_attr [`%qattr]; delta_only normal_steps] x
let vc_sound_norm
(cs:list code)
(qcs:with_wps cs)
(k:state -> Type0)
(s0:state)
: Ghost (state * fuel)
(requires
normal (vc_gen cs qcs k s0))
(ensures fun (sN, fN) ->
eval_code (Block cs) fN s0 == Some sN /\ k sN)
= vc_sound cs qcs k s0
////////////////////////////////////////////////////////////////////////////////
// Verifying a simple program
////////////////////////////////////////////////////////////////////////////////
[@@qattr]
let codes_Triple : list code =
[Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//1
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//2
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//3
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//4
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//5
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//6
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//7
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//8
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//9
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//10
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//11
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//1
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//2
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//3
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//4
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//5
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//6
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//7
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//8
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//9
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//10
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//11
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//1
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//2
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//3
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//4
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//5
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//6
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//7
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//8
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//9
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//10
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//11
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//1
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//2
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//3
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//4
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//5
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//6
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//7
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//8
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//9
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//10
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//11
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//1
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//2
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//3
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//4
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//5
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//6
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//7
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//8
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//9
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//10
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//11
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//1
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//2
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//3
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//4
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//5
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//6
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//7
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//8
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//9
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//10
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax;
//11
Ins (Add64 (OReg Rax) (OReg Rbx)); //add rax rbx;
Ins (Add64 (OReg Rbx) (OReg Rax))] //add rbx rax | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "MiniValeSemantics.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | MiniValeSemantics.with_wps MiniValeSemantics.codes_Triple | Prims.Tot | [
"total"
] | [] | [
"MiniValeSemantics.QSeq",
"MiniValeSemantics.Ins",
"MiniValeSemantics.Mov64",
"MiniValeSemantics.OReg",
"MiniValeSemantics.Rbx",
"MiniValeSemantics.Rax",
"Prims.Cons",
"MiniValeSemantics.code",
"MiniValeSemantics.Add64",
"Prims.Nil",
"MiniValeSemantics.inst_Move",
"MiniValeSemantics.inst_Add",
"MiniValeSemantics.QEmpty"
] | [] | false | false | false | true | false | let inst_Triple:with_wps codes_Triple =
| QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq (inst_Move (OReg Rbx) (OReg Rax))
(QSeq
(inst_Move (OReg Rbx) (OReg Rax))
(QSeq
(inst_Move (OReg Rbx)
(OReg Rax))
(QSeq
(inst_Move (OReg Rbx)
(OReg Rax))
(QSeq
(inst_Move (OReg Rbx)
(OReg Rax))
(QSeq
(inst_Move (OReg
Rbx)
(OReg Rax))
(QSeq
(inst_Move (OReg
Rbx)
(OReg Rax)
)
(QSeq
(inst_Move
(OReg
Rbx)
(OReg
Rax)
)
(QSeq
(inst_Move
(OReg
Rbx
)
(OReg
Rax
))
(QSeq
(inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Move
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QSeq
(
inst_Add
(
OReg
Rax
)
(
OReg
Rbx
)
)
(
QSeq
(
inst_Add
(
OReg
Rbx
)
(
OReg
Rax
)
)
(
QEmpty
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))
))))))))))))) | false |
Spec.P256.fst | Spec.P256.pk_compressed_from_raw | val pk_compressed_from_raw (pk: lbytes 64) : lbytes 33 | val pk_compressed_from_raw (pk: lbytes 64) : lbytes 33 | let pk_compressed_from_raw (pk:lbytes 64) : lbytes 33 =
let pk_x = sub pk 0 32 in
let pk_y = sub pk 32 32 in
let is_pk_y_odd = nat_from_bytes_be pk_y % 2 = 1 in // <==> pk_y % 2 = 1
let pk0 = if is_pk_y_odd then u8 0x03 else u8 0x02 in
concat (create 1 pk0) pk_x | {
"file_name": "specs/Spec.P256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 221,
"start_col": 0,
"start_line": 216
} | module Spec.P256
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Hash.Definitions
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module PL = Spec.P256.Lemmas
include Spec.P256.PointOps
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://eprint.iacr.org/2013/816.pdf *)
/// Elliptic curve scalar multiplication
let mk_p256_comm_monoid : LE.comm_monoid aff_point = {
LE.one = aff_point_at_inf;
LE.mul = aff_point_add;
LE.lemma_one = PL.aff_point_at_inf_lemma;
LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma;
LE.lemma_mul_comm = PL.aff_point_add_comm_lemma;
}
let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = {
SE.a_spec = aff_point;
SE.comm_monoid = mk_p256_comm_monoid;
SE.refl = to_aff_point;
}
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
let point_at_inf_c _ =
PL.to_aff_point_at_infinity_lemma ();
point_at_inf
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
let point_add_c p q =
PL.to_aff_point_add_lemma p q;
point_add p q
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
let point_double_c p =
PL.to_aff_point_double_lemma p;
point_double p
let mk_p256_concrete_ops : SE.concrete_ops proj_point = {
SE.to = mk_to_p256_comm_monoid;
SE.one = point_at_inf_c;
SE.mul = point_add_c;
SE.sqr = point_double_c;
}
// [a]P
let point_mul (a:qelem) (p:proj_point) : proj_point =
SE.exp_fw mk_p256_concrete_ops p 256 a 4
// [a]G
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
// [a1]G + [a2]P
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point =
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
/// ECDSA over the P256 elliptic curve
type hash_alg_ecdsa =
| NoHash
| Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512})
let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa
let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) =
Math.Lemmas.pow2_lt_compat 61 32;
Math.Lemmas.pow2_lt_compat 125 32
let min_input_length (a:hash_alg_ecdsa) : nat =
match a with | NoHash -> 32 | Hash a -> 0
val hash_ecdsa:
a:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length a}
-> msg:lseq uint8 msg_len ->
Tot (r:lbytes
(if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
let hash_ecdsa a msg_len msg =
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) =
let k_q = nat_from_bytes_be nonce in
let d_a = nat_from_bytes_be private_key in
let is_privkey_valid = 0 < d_a && d_a < order in
let is_nonce_valid = 0 < k_q && k_q < order in
if not (is_privkey_valid && is_nonce_valid) then None
else begin
let _X, _Y, _Z = point_mul_g k_q in
let x = _X /% _Z in
let r = x % order in
let kinv = qinv k_q in
let s = kinv *^ (m +^ r *^ d_a) in
let rb = nat_to_bytes_be 32 r in
let sb = nat_to_bytes_be 32 s in
if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool =
let pk = load_point public_key in
let r = nat_from_bytes_be sign_r in
let s = nat_from_bytes_be sign_s in
let is_r_valid = 0 < r && r < order in
let is_s_valid = 0 < s && s < order in
if not (Some? pk && is_r_valid && is_s_valid) then false
else begin
let sinv = qinv s in
let u1 = sinv *^ m in
let u2 = sinv *^ r in
let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in
if is_point_at_inf (_X, _Y, _Z) then false
else begin
let x = _X /% _Z in
x % order = r end
end
(*
_Z <> 0
q < prime < 2 * q
let x = _X /% _Z in x % q = r <==>
1. x = r <==> _X = r *% _Z
2. x - q = r <==> _X = (r + q) *% _Z
*)
val ecdsa_signature_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> private_key:lbytes 32
-> nonce:lbytes 32 ->
option (lbytes 64)
let ecdsa_signature_agile alg msg_len msg private_key nonce =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_verification_agile:
alg:hash_alg_ecdsa
-> msg_len:size_nat{msg_len >= min_input_length alg}
-> msg:lbytes msg_len
-> public_key:lbytes 64
-> signature_r:lbytes 32
-> signature_s:lbytes 32 ->
bool
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
let hashM = hash_ecdsa alg msg_len msg in
let m_q = nat_from_bytes_be (sub hashM 0 32) % order in
ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
/// ECDH over the P256 elliptic curve
let secret_to_public (private_key:lbytes 32) : option (lbytes 64) =
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if is_sk_valid then
let pk = point_mul_g sk in
Some (point_store pk)
else None
let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) =
let pk = load_point their_public_key in
let sk = nat_from_bytes_be private_key in
let is_sk_valid = 0 < sk && sk < order in
if Some? pk && is_sk_valid then
let ss = point_mul sk (Some?.v pk) in
Some (point_store ss)
else None
/// Parsing and Serializing public keys
// raw = [ x; y ], 64 bytes
// uncompressed = [ 0x04; x; y ], 65 bytes
// compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes
let validate_public_key (pk:lbytes 64) : bool =
Some? (load_point pk)
let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) =
if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64)
let pk_uncompressed_from_raw (pk:lbytes 64) : lbytes 65 =
concat (create 1 (u8 0x04)) pk
let pk_compressed_to_raw (pk:lbytes 33) : option (lbytes 64) =
let pk_x = sub pk 1 32 in
match (aff_point_decompress pk) with
| Some (x, y) -> Some (concat #_ #32 #32 pk_x (nat_to_bytes_be 32 y))
| None -> None | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"Spec.P256.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Exponentiation.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Spec.P256.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "PL"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | pk: Lib.ByteSequence.lbytes 64 -> Lib.ByteSequence.lbytes 33 | Prims.Tot | [
"total"
] | [] | [
"Lib.ByteSequence.lbytes",
"Lib.Sequence.concat",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.create",
"Lib.IntTypes.int_t",
"Lib.IntTypes.u8",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Lib.ByteSequence.nat_from_bytes_be",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub"
] | [] | false | false | false | false | false | let pk_compressed_from_raw (pk: lbytes 64) : lbytes 33 =
| let pk_x = sub pk 0 32 in
let pk_y = sub pk 32 32 in
let is_pk_y_odd = nat_from_bytes_be pk_y % 2 = 1 in
let pk0 = if is_pk_y_odd then u8 0x03 else u8 0x02 in
concat (create 1 pk0) pk_x | false |
LowParse.Tot.Bytes.fst | LowParse.Tot.Bytes.parse_all_bytes | val parse_all_bytes : LowParse.Spec.Base.tot_parser LowParse.Spec.Bytes.parse_all_bytes_kind FStar.Bytes.bytes | let parse_all_bytes = tot_parse_all_bytes | {
"file_name": "src/lowparse/LowParse.Tot.Bytes.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 41,
"end_line": 7,
"start_col": 0,
"start_line": 7
} | module LowParse.Tot.Bytes
include LowParse.Spec.Bytes
include LowParse.Tot.Combinators
include LowParse.Tot.Int | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Tot.Int.fst.checked",
"LowParse.Tot.Combinators.fst.checked",
"LowParse.Spec.Bytes.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Tot.Bytes.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Tot.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Tot.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.tot_parser LowParse.Spec.Bytes.parse_all_bytes_kind FStar.Bytes.bytes | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Bytes.tot_parse_all_bytes"
] | [] | false | false | false | true | false | let parse_all_bytes =
| tot_parse_all_bytes | false |
|
SteelNull.fst | SteelNull.main | val main: Prims.unit -> SteelT Int32.t emp (fun _ -> emp) | val main: Prims.unit -> SteelT Int32.t emp (fun _ -> emp) | let main () : SteelT Int32.t emp (fun _ -> emp) =
let r = null #UInt32.t in
if is_null r then
return 0l
else
return 1l | {
"file_name": "share/steel/tests/krml/SteelNull.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 12,
"start_col": 0,
"start_line": 7
} | module SteelNull
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Reference | {
"checked_file": "/",
"dependencies": [
"Steel.Reference.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int32.fsti.checked"
],
"interface_file": false,
"source_file": "SteelNull.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | _: Prims.unit -> Steel.Effect.SteelT FStar.Int32.t | Steel.Effect.SteelT | [] | [] | [
"Prims.unit",
"Steel.Reference.is_null",
"FStar.UInt32.t",
"Steel.Effect.Atomic.return",
"FStar.Int32.t",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__mult",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.req",
"Steel.Effect.Common.rm",
"FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit",
"Steel.Effect.Common.emp",
"FStar.Int32.__int_to_t",
"Prims.bool",
"Steel.Reference.ref",
"Steel.Reference.null"
] | [] | false | true | false | false | false | let main () : SteelT Int32.t emp (fun _ -> emp) =
| let r = null #UInt32.t in
if is_null r then return 0l else return 1l | false |
Pulse.C.Types.Struct.fsti | Pulse.C.Types.Struct.define_struct | val define_struct
(n: string)
(#tf #tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot Type0 | val define_struct
(n: string)
(#tf #tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot Type0 | let define_struct (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= define_struct0 tn #tf n fields | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Struct.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 12,
"start_col": 0,
"start_line": 11
} | module Pulse.C.Types.Struct
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
// To be extracted as: struct t { fields ... }
[@@noextract_to "krml"] // primitive
val define_struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Struct.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.string -> fields: Pulse.C.Types.Fields.nonempty_field_description_t tf -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.squash",
"FStar.Pervasives.norm",
"Pulse.C.Typestring.norm_typestring",
"Prims.eq2",
"Pulse.C.Typestring.mk_string_t",
"Pulse.C.Types.Fields.nonempty_field_description_t",
"Pulse.C.Types.Struct.define_struct0"
] | [] | false | false | false | false | true | let define_struct
(n: string)
(#tf #tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot Type0 =
| define_struct0 tn #tf n fields | false |
Pulse.C.Types.Struct.fsti | Pulse.C.Types.Struct.struct_t | val struct_t
(#tf: Type0)
(n: string)
(#tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot Type0 | val struct_t
(#tf: Type0)
(n: string)
(#tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot Type0 | let struct_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= struct_t0 tn #tf n fields | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Struct.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 27,
"end_line": 19,
"start_col": 0,
"start_line": 18
} | module Pulse.C.Types.Struct
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
// To be extracted as: struct t { fields ... }
[@@noextract_to "krml"] // primitive
val define_struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_struct (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= define_struct0 tn #tf n fields
// To be extracted as: struct t
[@@noextract_to "krml"] // primitive
val struct_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Struct.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.string -> fields: Pulse.C.Types.Fields.nonempty_field_description_t tf -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.squash",
"FStar.Pervasives.norm",
"Pulse.C.Typestring.norm_typestring",
"Prims.eq2",
"Pulse.C.Typestring.mk_string_t",
"Pulse.C.Types.Fields.nonempty_field_description_t",
"Pulse.C.Types.Struct.struct_t0"
] | [] | false | false | false | false | true | let struct_t
(#tf: Type0)
(n: string)
(#tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot Type0 =
| struct_t0 tn #tf n fields | false |
Pulse.C.Types.Struct.fsti | Pulse.C.Types.Struct.struct | val struct
(#tf: Type0)
(n: string)
(#tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot (typedef (struct_t0 tn n fields)) | val struct
(#tf: Type0)
(n: string)
(#tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot (typedef (struct_t0 tn n fields)) | let struct (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot (typedef (struct_t0 tn n fields))
= struct0 tn #tf n fields | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Struct.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 25,
"end_line": 92,
"start_col": 0,
"start_line": 91
} | module Pulse.C.Types.Struct
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
// To be extracted as: struct t { fields ... }
[@@noextract_to "krml"] // primitive
val define_struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_struct (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= define_struct0 tn #tf n fields
// To be extracted as: struct t
[@@noextract_to "krml"] // primitive
val struct_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let struct_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= struct_t0 tn #tf n fields
val struct_set_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (f: field_t fields) (v: fields.fd_type f) (s: struct_t0 tn n fields) : GTot (struct_t0 tn n fields)
val struct_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
: GTot (fields.fd_type field)
val struct_eq
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s1 s2: struct_t0 tn n fields)
: Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (s1 == s2)) /\
(y <==> (forall field . struct_get_field s1 field == struct_get_field s2 field))
))
val struct_get_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(struct_get_field (struct_set_field field v s) field == v)
[SMTPat (struct_get_field (struct_set_field field v s) field)]
val struct_get_field_other
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(requires (field' <> field))
(ensures (struct_get_field (struct_set_field field v s) field' == struct_get_field s field'))
let struct_get_field_pat
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(struct_get_field (struct_set_field field v s) field' == (if field' = field then v else struct_get_field s field'))
[SMTPat (struct_get_field (struct_set_field field v s) field')]
= if field' = field
then ()
else struct_get_field_other s field v field'
[@@noextract_to "krml"] // proof-only
val struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot (typedef (struct_t0 tn n fields))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Struct.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.string -> fields: Pulse.C.Types.Fields.nonempty_field_description_t tf
-> Pulse.C.Types.Base.typedef (Pulse.C.Types.Struct.struct_t0 tn n fields) | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.squash",
"FStar.Pervasives.norm",
"Pulse.C.Typestring.norm_typestring",
"Prims.eq2",
"Pulse.C.Typestring.mk_string_t",
"Pulse.C.Types.Fields.nonempty_field_description_t",
"Pulse.C.Types.Struct.struct0",
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Struct.struct_t0"
] | [] | false | false | false | false | false | let struct
(#tf: Type0)
(n: string)
(#tn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn)))
(fields: nonempty_field_description_t tf)
: Tot (typedef (struct_t0 tn n fields)) =
| struct0 tn #tf n fields | false |
Vale.Def.Words.Two.fst | Vale.Def.Words.Two.nat_to_two_to_nat | val nat_to_two_to_nat (n1 n2:nat32) : Lemma
(nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2)
[SMTPat (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)))] | val nat_to_two_to_nat (n1 n2:nat32) : Lemma
(nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2)
[SMTPat (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)))] | let nat_to_two_to_nat (n1 n2:nat32) : Lemma
(nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2)
=
let n = n1 + n2 * pow2_32 in
assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n);
assert (0 <= n);
assert (n < pow2_64);
assert (two_to_nat 32 (Mktwo n1 n2) == n);
assert_norm (pow2_norm 32 == pow2_32);
//assert_norm (pow2_norm (2 * 32) == pow2_64);
assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32));
lemma_fundamental_div_mod n;
() | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Two.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 22,
"start_col": 0,
"start_line": 10
} | module Vale.Def.Words.Two
open FStar.Mul
open Vale.Lib.Meta
let lemma_fundamental_div_mod (x:nat64) :
Lemma (x = x % pow2_32 + pow2_32 * ((x / pow2_32) % pow2_32))
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Meta.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Two.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | n1: Vale.Def.Words_s.nat32 -> n2: Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Two_s.nat_to_two 32
(Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words_s.Mktwo n1 n2)) ==
Vale.Def.Words_s.Mktwo n1 n2)
[
SMTPat (Vale.Def.Words.Two_s.nat_to_two 32
(Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words_s.Mktwo n1 n2)))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.nat32",
"Prims.unit",
"Vale.Def.Words.Two.lemma_fundamental_div_mod",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.Def.Words_s.Mktwo",
"Prims.op_Modulus",
"Vale.Def.Words_s.pow2_32",
"Prims.op_Division",
"Prims.int",
"Vale.Def.Words_s.pow2_norm",
"Prims._assert",
"Vale.Def.Words.Two_s.two_to_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.Def.Words_s.pow2_64",
"Prims.op_LessThanOrEqual",
"Vale.Def.Words_s.int_to_natN",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let nat_to_two_to_nat (n1 n2: nat32)
: Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) =
| let n = n1 + n2 * pow2_32 in
assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n);
assert (0 <= n);
assert (n < pow2_64);
assert (two_to_nat 32 (Mktwo n1 n2) == n);
assert_norm (pow2_norm 32 == pow2_32);
assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32));
lemma_fundamental_div_mod n;
() | false |
Vale.Def.Words.Two.fst | Vale.Def.Words.Two.two_to_nat_to_two | val two_to_nat_to_two (n:nat64) : Lemma
(two_to_nat 32 (nat_to_two 32 n) == n)
[SMTPat (two_to_nat 32 (nat_to_two 32 n))] | val two_to_nat_to_two (n:nat64) : Lemma
(two_to_nat 32 (nat_to_two 32 n) == n)
[SMTPat (two_to_nat 32 (nat_to_two 32 n))] | let two_to_nat_to_two (n:nat64) =
let n1 = n % (pow2_32) in
let n2 = (n/(pow2_32)) % (pow2_32) in
let n_f = two_to_nat 32 (Mktwo n1 n2) in
assert_norm (n == n1 + n2 * pow2_32) | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Two.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 28,
"start_col": 0,
"start_line": 24
} | module Vale.Def.Words.Two
open FStar.Mul
open Vale.Lib.Meta
let lemma_fundamental_div_mod (x:nat64) :
Lemma (x = x % pow2_32 + pow2_32 * ((x / pow2_32) % pow2_32))
=
()
let nat_to_two_to_nat (n1 n2:nat32) : Lemma
(nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2)
=
let n = n1 + n2 * pow2_32 in
assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n);
assert (0 <= n);
assert (n < pow2_64);
assert (two_to_nat 32 (Mktwo n1 n2) == n);
assert_norm (pow2_norm 32 == pow2_32);
//assert_norm (pow2_norm (2 * 32) == pow2_64);
assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32));
lemma_fundamental_div_mod n;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Meta.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Two.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Vale.Def.Words_s.nat64
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words.Two_s.nat_to_two 32 n) == n)
[SMTPat (Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words.Two_s.nat_to_two 32 n))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.nat64",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.pow2_32",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Prims.op_Multiply",
"Vale.Def.Words.Two_s.two_to_nat",
"Vale.Def.Words_s.Mktwo",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.unit"
] | [] | true | false | true | false | false | let two_to_nat_to_two (n: nat64) =
| let n1 = n % (pow2_32) in
let n2 = (n / (pow2_32)) % (pow2_32) in
let n_f = two_to_nat 32 (Mktwo n1 n2) in
assert_norm (n == n1 + n2 * pow2_32) | false |
Vale.Def.Words.Two.fst | Vale.Def.Words.Two.two_to_nat_32_injective | val two_to_nat_32_injective (_:unit) : Lemma
(forall (x x':two (natN (pow2_norm 32))).{:pattern two_to_nat 32 x; two_to_nat 32 x'}
two_to_nat 32 x == two_to_nat 32 x' ==> x == x') | val two_to_nat_32_injective (_:unit) : Lemma
(forall (x x':two (natN (pow2_norm 32))).{:pattern two_to_nat 32 x; two_to_nat 32 x'}
two_to_nat 32 x == two_to_nat 32 x' ==> x == x') | let two_to_nat_32_injective () =
generic_injective_proof (two_to_nat 32) (nat_to_two 32) (fun x -> nat_to_two_to_nat x.lo x.hi) | {
"file_name": "vale/code/lib/util/Vale.Def.Words.Two.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 31,
"start_col": 0,
"start_line": 30
} | module Vale.Def.Words.Two
open FStar.Mul
open Vale.Lib.Meta
let lemma_fundamental_div_mod (x:nat64) :
Lemma (x = x % pow2_32 + pow2_32 * ((x / pow2_32) % pow2_32))
=
()
let nat_to_two_to_nat (n1 n2:nat32) : Lemma
(nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2)
=
let n = n1 + n2 * pow2_32 in
assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n);
assert (0 <= n);
assert (n < pow2_64);
assert (two_to_nat 32 (Mktwo n1 n2) == n);
assert_norm (pow2_norm 32 == pow2_32);
//assert_norm (pow2_norm (2 * 32) == pow2_64);
assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32));
lemma_fundamental_div_mod n;
()
let two_to_nat_to_two (n:nat64) =
let n1 = n % (pow2_32) in
let n2 = (n/(pow2_32)) % (pow2_32) in
let n_f = two_to_nat 32 (Mktwo n1 n2) in
assert_norm (n == n1 + n2 * pow2_32) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Meta.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Vale.Def.Words.Two.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
forall (x: Vale.Def.Words_s.two (Vale.Def.Words_s.natN (Vale.Def.Words_s.pow2_norm 32)))
(x': Vale.Def.Words_s.two (Vale.Def.Words_s.natN (Vale.Def.Words_s.pow2_norm 32))).
{:pattern Vale.Def.Words.Two_s.two_to_nat 32 x; Vale.Def.Words.Two_s.two_to_nat 32 x'}
Vale.Def.Words.Two_s.two_to_nat 32 x == Vale.Def.Words.Two_s.two_to_nat 32 x' ==> x == x') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"Vale.Lib.Meta.generic_injective_proof",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words.Two_s.two_to_nat",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.Def.Words.Two.nat_to_two_to_nat",
"Vale.Def.Words_s.__proj__Mktwo__item__lo",
"Vale.Def.Words_s.__proj__Mktwo__item__hi"
] | [] | false | false | true | false | false | let two_to_nat_32_injective () =
| generic_injective_proof (two_to_nat 32) (nat_to_two 32) (fun x -> nat_to_two_to_nat x.lo x.hi) | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.proj_g_pow2_64_lseq_lemma | val proj_g_pow2_64_lseq_lemma: unit ->
Lemma (point_inv_seq proj_g_pow2_64_lseq /\
S.to_aff_point (from_mont_point (as_point_nat_seq proj_g_pow2_64_lseq)) == g_pow2_64) | val proj_g_pow2_64_lseq_lemma: unit ->
Lemma (point_inv_seq proj_g_pow2_64_lseq /\
S.to_aff_point (from_mont_point (as_point_nat_seq proj_g_pow2_64_lseq)) == g_pow2_64) | let proj_g_pow2_64_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
proj_g_pow2_64_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_64 | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 171,
"start_col": 0,
"start_line": 168
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list
let proj_g_pow2_192_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list
val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff)
let proj_g_pow2_64_lemma () =
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_128_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff)
let proj_g_pow2_128_lemma () =
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_128_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff)
let proj_g_pow2_192_lemma () =
lemma_proj_g_pow2_192_eval ();
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_192_lemma S.mk_p256_concrete_ops S.base_point | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
Hacl.Impl.P256.Point.point_inv_seq Hacl.P256.PrecompTable.proj_g_pow2_64_lseq /\
Spec.P256.PointOps.to_aff_point (Hacl.Impl.P256.Point.from_mont_point (Hacl.Impl.P256.Point.as_point_nat_seq
Hacl.P256.PrecompTable.proj_g_pow2_64_lseq)) ==
Hacl.P256.PrecompTable.g_pow2_64) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"Hacl.Spec.P256.PrecompTable.proj_point_to_list_lemma",
"Hacl.P256.PrecompTable.proj_g_pow2_64",
"Hacl.P256.PrecompTable.proj_g_pow2_64_lemma",
"FStar.Pervasives.normalize_term_spec",
"Hacl.Spec.P256.PrecompTable.point_list",
"Hacl.Spec.P256.PrecompTable.proj_point_to_list"
] | [] | true | false | true | false | false | let proj_g_pow2_64_lseq_lemma () =
| normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
proj_g_pow2_64_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_64 | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.proj_g_pow2_128_list | val proj_g_pow2_128_list:SPTK.point_list | val proj_g_pow2_128_list:SPTK.point_list | let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128) | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 121,
"start_col": 0,
"start_line": 120
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Spec.P256.PrecompTable.point_list | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize_term",
"Hacl.Spec.P256.PrecompTable.point_list",
"Hacl.Spec.P256.PrecompTable.proj_point_to_list",
"Hacl.P256.PrecompTable.proj_g_pow2_128"
] | [] | false | false | false | true | false | let proj_g_pow2_128_list:SPTK.point_list =
| normalize_term (SPTK.proj_point_to_list proj_g_pow2_128) | false |
Pulse.C.Types.Struct.fsti | Pulse.C.Types.Struct.struct_get_field_pat | val struct_get_field_pat
(#tn #tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(struct_get_field (struct_set_field field v s) field' ==
(if field' = field then v else struct_get_field s field'))
[SMTPat (struct_get_field (struct_set_field field v s) field')] | val struct_get_field_pat
(#tn #tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(struct_get_field (struct_set_field field v s) field' ==
(if field' = field then v else struct_get_field s field'))
[SMTPat (struct_get_field (struct_set_field field v s) field')] | let struct_get_field_pat
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(struct_get_field (struct_set_field field v s) field' == (if field' = field then v else struct_get_field s field'))
[SMTPat (struct_get_field (struct_set_field field v s) field')]
= if field' = field
then ()
else struct_get_field_other s field v field' | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Struct.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 84,
"start_col": 0,
"start_line": 70
} | module Pulse.C.Types.Struct
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
// To be extracted as: struct t { fields ... }
[@@noextract_to "krml"] // primitive
val define_struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_struct (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= define_struct0 tn #tf n fields
// To be extracted as: struct t
[@@noextract_to "krml"] // primitive
val struct_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let struct_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= struct_t0 tn #tf n fields
val struct_set_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (f: field_t fields) (v: fields.fd_type f) (s: struct_t0 tn n fields) : GTot (struct_t0 tn n fields)
val struct_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
: GTot (fields.fd_type field)
val struct_eq
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s1 s2: struct_t0 tn n fields)
: Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (s1 == s2)) /\
(y <==> (forall field . struct_get_field s1 field == struct_get_field s2 field))
))
val struct_get_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(struct_get_field (struct_set_field field v s) field == v)
[SMTPat (struct_get_field (struct_set_field field v s) field)]
val struct_get_field_other
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(requires (field' <> field))
(ensures (struct_get_field (struct_set_field field v s) field' == struct_get_field s field')) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Struct.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: Pulse.C.Types.Struct.struct_t0 tn n fields ->
field: Pulse.C.Types.Fields.field_t fields ->
v: Mkfield_description_t?.fd_type fields field ->
field': Pulse.C.Types.Fields.field_t fields
-> FStar.Pervasives.Lemma
(ensures
Pulse.C.Types.Struct.struct_get_field (Pulse.C.Types.Struct.struct_set_field field v s)
field' ==
(match field' = field with
| true -> v
| _ -> Pulse.C.Types.Struct.struct_get_field s field'))
[
SMTPat (Pulse.C.Types.Struct.struct_get_field (Pulse.C.Types.Struct.struct_set_field field
v
s)
field')
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.string",
"Pulse.C.Types.Fields.nonempty_field_description_t",
"Pulse.C.Types.Struct.struct_t0",
"Pulse.C.Types.Fields.field_t",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Prims.op_Equality",
"Prims.bool",
"Pulse.C.Types.Struct.struct_get_field_other",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Pulse.C.Types.Struct.struct_get_field",
"Pulse.C.Types.Struct.struct_set_field",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let struct_get_field_pat
(#tn #tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(struct_get_field (struct_set_field field v s) field' ==
(if field' = field then v else struct_get_field s field'))
[SMTPat (struct_get_field (struct_set_field field v s) field')] =
| if field' = field then () else struct_get_field_other s field v field' | false |
Hacl.HPKE.Curve51_CP256_SHA256.fsti | Hacl.HPKE.Curve51_CP256_SHA256.cs | val cs:S.ciphersuite | val cs:S.ciphersuite | let cs:S.ciphersuite = (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256) | {
"file_name": "code/hpke/Hacl.HPKE.Curve51_CP256_SHA256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 102,
"end_line": 10,
"start_col": 0,
"start_line": 10
} | module Hacl.HPKE.Curve51_CP256_SHA256
open Hacl.Impl.HPKE
module S = Spec.Agile.HPKE
module DH = Spec.Agile.DH
module AEAD = Spec.Agile.AEAD
module Hash = Spec.Agile.Hash | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"Spec.Agile.DH.fst.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"Hacl.Impl.HPKE.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Curve51_CP256_SHA256.fsti"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Agile.HPKE.ciphersuite | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.Mktuple4",
"Spec.Agile.DH.algorithm",
"Spec.Agile.HPKE.hash_algorithm",
"Spec.Agile.HPKE.aead",
"Spec.Hash.Definitions.hash_alg",
"Spec.Agile.DH.DH_Curve25519",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Agile.HPKE.Seal",
"Spec.Agile.AEAD.CHACHA20_POLY1305"
] | [] | false | false | false | true | false | let cs:S.ciphersuite =
| (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256) | false |
Pulse.C.Types.Struct.fsti | Pulse.C.Types.Struct.struct_field1 | val struct_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' ->
(pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) **
pts_to r' (struct_get_field v field)) **
has_struct_field r field r') | val struct_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' ->
(pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) **
pts_to r' (struct_get_field v field)) **
has_struct_field r field r') | let struct_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (struct_get_field v field) ** has_struct_field r field r')
= struct_field0 t' r field td' | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Struct.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 268,
"start_col": 0,
"start_line": 253
} | module Pulse.C.Types.Struct
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
// To be extracted as: struct t { fields ... }
[@@noextract_to "krml"] // primitive
val define_struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_struct (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= define_struct0 tn #tf n fields
// To be extracted as: struct t
[@@noextract_to "krml"] // primitive
val struct_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let struct_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= struct_t0 tn #tf n fields
val struct_set_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (f: field_t fields) (v: fields.fd_type f) (s: struct_t0 tn n fields) : GTot (struct_t0 tn n fields)
val struct_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
: GTot (fields.fd_type field)
val struct_eq
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s1 s2: struct_t0 tn n fields)
: Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (s1 == s2)) /\
(y <==> (forall field . struct_get_field s1 field == struct_get_field s2 field))
))
val struct_get_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(struct_get_field (struct_set_field field v s) field == v)
[SMTPat (struct_get_field (struct_set_field field v s) field)]
val struct_get_field_other
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(requires (field' <> field))
(ensures (struct_get_field (struct_set_field field v s) field' == struct_get_field s field'))
let struct_get_field_pat
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(struct_get_field (struct_set_field field v s) field' == (if field' = field then v else struct_get_field s field'))
[SMTPat (struct_get_field (struct_set_field field v s) field')]
= if field' = field
then ()
else struct_get_field_other s field v field'
[@@noextract_to "krml"] // proof-only
val struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot (typedef (struct_t0 tn n fields))
inline_for_extraction
[@@noextract_to "krml"; norm_field_attr] // proof-only
let struct (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot (typedef (struct_t0 tn n fields))
= struct0 tn #tf n fields
val struct_get_field_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: nonempty_field_description_t tf)
(field: field_t fields)
: Lemma
(struct_get_field (unknown (struct0 tn n fields)) field == unknown (fields.fd_typedef field))
[SMTPat (struct_get_field (unknown (struct0 tn n fields)) field)]
val struct_get_field_uninitialized
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: nonempty_field_description_t tf)
(field: field_t fields)
: Lemma
(struct_get_field (uninitialized (struct0 tn n fields)) field == uninitialized (fields.fd_typedef field))
[SMTPat (struct_get_field (uninitialized (struct0 tn n fields)) field)]
val has_struct_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: Tot vprop
val has_struct_field_prop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_struct_field r field r')
(fun _ -> has_struct_field r field r' ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
val has_struct_field_dup
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_struct_field r field r')
(fun _ -> has_struct_field r field r' ** has_struct_field r field r')
val has_struct_field_inj
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t1: Type0)
(#td1: typedef t1)
(r1: ref td1)
(#t2: Type0)
(#td2: typedef t2)
(r2: ref td2)
: stt_ghost (squash (t1 == t2 /\ td1 == td2))
(has_struct_field r field r1 ** has_struct_field r field r2)
(fun _ -> has_struct_field r field r1 ** has_struct_field r field r2 ** ref_equiv r1 (coerce_eq () r2))
val has_struct_field_equiv_from
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r1: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
(r2: ref (struct0 tn n fields))
: stt_ghost unit
(ref_equiv r1 r2 ** has_struct_field r1 field r')
(fun _ -> ref_equiv r1 r2 ** has_struct_field r2 field r')
val has_struct_field_equiv_to
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r1' r2': ref td')
: stt_ghost unit
(ref_equiv r1' r2' ** has_struct_field r field r1')
(fun _ -> ref_equiv r1' r2' ** has_struct_field r field r2')
val ghost_struct_field_focus
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost (squash (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
(has_struct_field r field r' ** pts_to r v)
(fun _ -> has_struct_field r field r' ** pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (Ghost.hide (coerce_eq () (struct_get_field v field))))
val ghost_struct_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
: stt_ghost (Ghost.erased (ref (fields.fd_typedef field)))
(pts_to r v)
(fun r' -> pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (struct_get_field v field) ** has_struct_field r field r')
[@@noextract_to "krml"] // primitive
val struct_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td')
(pts_to r v)
(fun r' -> pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (Ghost.hide (coerce_eq () (struct_get_field v field))) ** has_struct_field r field r')
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Struct.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t': Type0 ->
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Struct.struct0 tn n fields) ->
field: Pulse.C.Types.Fields.field_t fields ->
td': Pulse.C.Types.Base.typedef t' ->
sq_t': Prims.squash (t' == Mkfield_description_t?.fd_type fields field) ->
sq_td': Prims.squash (td' == Mkfield_description_t?.fd_typedef fields field)
-> Pulse.Lib.Core.stt (Pulse.C.Types.Base.ref td')
(Pulse.C.Types.Base.pts_to r v)
(fun r' ->
(Pulse.C.Types.Base.pts_to r
(FStar.Ghost.hide (Pulse.C.Types.Struct.struct_set_field field
(Pulse.C.Types.Base.unknown (Mkfield_description_t?.fd_typedef fields field))
(FStar.Ghost.reveal v))) **
Pulse.C.Types.Base.pts_to r'
(FStar.Ghost.hide (Pulse.C.Types.Struct.struct_get_field (FStar.Ghost.reveal v) field))) **
Pulse.C.Types.Struct.has_struct_field r field r') | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Pulse.C.Types.Fields.nonempty_field_description_t",
"FStar.Ghost.erased",
"Pulse.C.Types.Struct.struct_t0",
"Pulse.C.Types.Base.ref",
"Pulse.C.Types.Struct.struct0",
"Pulse.C.Types.Fields.field_t",
"Pulse.C.Types.Base.typedef",
"Prims.squash",
"Prims.eq2",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef",
"Pulse.C.Types.Struct.struct_field0",
"Pulse.Lib.Core.stt",
"Pulse.C.Types.Base.pts_to",
"Pulse.Lib.Core.op_Star_Star",
"FStar.Ghost.hide",
"Pulse.C.Types.Struct.struct_set_field",
"Pulse.C.Types.Base.unknown",
"FStar.Ghost.reveal",
"Pulse.C.Types.Struct.struct_get_field",
"Pulse.C.Types.Struct.has_struct_field",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let struct_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' ->
(pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) **
pts_to r' (struct_get_field v field)) **
has_struct_field r field r') =
| struct_field0 t' r field td' | false |
FStar.Buffer.fst | FStar.Buffer.blit | val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) ==
Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) )) | val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) ==
Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) )) | let rec blit #t a idx_a b idx_b len =
let h0 = HST.get () in
if len =^ 0ul then ()
else
begin
let len' = len -^ 1ul in
blit #t a idx_a b idx_b len';
let z = a.(idx_a +^ len') in
b.(idx_b +^ len') <- z;
let h1 = HST.get() in
Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len');
Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b));
Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b))
end | {
"file_name": "ulib/legacy/FStar.Buffer.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 7,
"end_line": 1186,
"start_col": 0,
"start_line": 1173
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Buffer
open FStar.Seq
open FStar.UInt32
module Int32 = FStar.Int32
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Ghost
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--initial_fuel 0 --max_fuel 0"
//17-01-04 usage? move to UInt?
let lemma_size (x:int) : Lemma (requires (UInt.size x n))
(ensures (x >= 0))
[SMTPat (UInt.size x n)]
= ()
let lseq (a: Type) (l: nat) : Type =
(s: seq a { Seq.length s == l } )
(* Buffer general type, fully implemented on FStar's arrays *)
noeq private type _buffer (a:Type) =
| MkBuffer: max_length:UInt32.t
-> content:reference (lseq a (v max_length))
-> idx:UInt32.t
-> length:UInt32.t{v idx + v length <= v max_length}
-> _buffer a
(* Exposed buffer type *)
type buffer (a:Type) = _buffer a
(* Ghost getters for specifications *)
// TODO: remove `contains` after replacing all uses with `live`
let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content
let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h
(* In most cases `as_seq` should be used instead of this one. *)
let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content
let max_length #a (b:buffer a) : GTot nat = v b.max_length
let length #a (b:buffer a) : GTot nat = v b.length
let idx #a (b:buffer a) : GTot nat = v b.idx
//17-01-04 rename to container or ref?
let content #a (b:buffer a) :
GTot (reference (lseq a (max_length b))) = b.content
(* Lifting from buffer to reference *)
let as_ref #a (b:buffer a) = as_ref (content b)
let as_addr #a (b:buffer a) = as_addr (content b)
let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b)
(* Liveliness condition, necessary for any computation on the buffer *)
let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content
let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h
val recall: #a:Type
-> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit
(requires (fun m -> True))
(ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
let recall #a b = recall b.content
(* Ghostly access an element of the array, or the full underlying sequence *)
let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) =
Seq.slice (sel h b) (idx b) (idx b + length b)
let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a =
Seq.index (as_seq h b) i
(* Equality predicate on buffer contents, without quantifiers *)
//17-01-04 revise comment? rename?
let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
(* y is included in x / x contains y *)
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 =
x.max_length == y.max_length /\
x.content === y.content /\
idx y >= idx x /\
idx x + length x >= idx y + length y
let includes_live #a h (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y))
(ensures (live h x <==> live h y))
= ()
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y);
Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y)
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= ()
(* Disjointness between two buffers *)
let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 =
frameOf x =!= frameOf y \/ as_addr x =!= as_addr y
\/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\
(idx x + length x <= idx y \/ idx y + length y <= idx x))
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= ()
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
let lemma_live_disjoint #a #a' h b b' = ()
(* Heterogeneous buffer type *)
noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer
(* let empty : TSet.set abuffer = TSet.empty #abuffer *)
let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b)
(* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *)
(* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *)
let op_Bang_Bang = TSet.singleton
let op_Plus_Plus = TSet.union
(* Maps a set of buffer to the set of their references *)
assume val arefs: TSet.set abuffer -> Tot (Set.set nat)
assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))}
Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma
(requires (s == TSet.empty #abuffer))
(ensures (arefs s == Set.empty #nat))
[SMTPat (arefs s)]
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires True)
(ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2)))
[SMTPatOr [
[SMTPat (arefs (s2 ++ s1))];
[SMTPat (arefs (s1 ++ s2))]
]]
let lemma_arefs_2 s1 s2 =
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma
(requires (TSet.subset s1 s2))
(ensures (Set.subset (arefs s1) (arefs s2)))
let lemma_arefs_3 s1 s2 = ()
(* General disjointness predicate between a buffer and a set of heterogeneous buffers *)
let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) =
forall b'. TSet.mem b' bufs ==> disjoint b b'.b
(* General disjointness predicate between a buffer and a set of heterogeneous references *)
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) =
~(Set.mem (as_addr b) set)
(* Similar but specialized disjointness predicates *)
let disjoint_1 a b = disjoint a b
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint b b'))
(ensures (disjoint_from_bufs b (only b')))
let disjoint_only_lemma #a #a' b b' = ()
(* Fully general modifies clause *)
let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (Set.union (arefs bufs) refs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs
/\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b)))
(* Fully general modifies clause for buffer sets *)
let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 =
(forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==>
(HS.modifies_ref rid (arefs bufs) h h' /\
(forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)}
(frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b))))
(* General modifies clause for buffers only *)
let modifies_bufs rid buffs h h' =
modifies_ref rid (arefs buffs) h h'
/\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_none h h' =
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
(* Specialized clauses for small numbers of buffers *)
let modifies_buf_0 rid h h' =
modifies_ref rid (Set.empty #nat) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' =
modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' =
modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb)
==> equal h bb h' bb /\ live h' bb)
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat =
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' =
modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h'
/\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb)
==> equal h bb h' bb /\ live h' bb)
(* General lemmas for the modifies_bufs clause *)
let lemma_modifies_bufs_trans rid bufs h0 h1 h2 :
Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2))
(ensures (modifies_bufs rid bufs h0 h2))
[SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)]
= ()
let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 :
Lemma
(requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1))
(ensures (modifies_bufs rid bufs h0 h1))
[SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)]
= ()
val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (disjoint_from_bufs b (bufs ++ (only b')) ))
(ensures (disjoint_from_bufs b bufs))
[SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)]
let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = ()
val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma
(requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs))
(ensures (disjoint_from_bufs b (bufs ++ (only b'))))
[SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)]
let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = ()
(* Specialized lemmas *)
let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_0 rid h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_1 rid b h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)]
= ()
let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)]
= ()
let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)]
= ()
let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2))
(ensures (modifies_buf_2 rid b b' h0 h2))
[SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)]
= ()
let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2))
(ensures (modifies_buf_3 rid b b' b'' h0 h2))
[SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)]
= ()
let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) :
Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2))
(ensures (modifies_buf_4 rid b b' b'' b''' h0 h2))
[SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)]
= ()
(* TODO: complete with specialized versions of every general lemma *)
(* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *)
(* NB: those clauses are made abstract in order to make verification faster
// Lemmas follow to allow the programmer to make use of the real definition
// of those predicates in a general setting *)
let modifies_0 (h0 h1:mem) :Type0 =
modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1
(* This one is very generic: it says
// * - some references have changed in the frame of b, but
// * - among all buffers in this frame, b is the only one that changed. *)
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 =
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 =
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
(* Lemmas introducing the 'modifies' predicates *)
let lemma_intro_modifies_0 h0 h1 : Lemma
(requires (modifies_one (HS.get_tip h0) h0 h1
/\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_0 h0 h1))
= ()
let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (let rid = frameOf b in
modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_1 b h0 h1))
= ()
let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
(ensures (modifies_2_1 b h0 h1))
= ()
let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))))
(ensures (modifies_2 b b' h0 h1))
= ()
let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))))
(ensures (modifies_3 b b' b'' h0 h1))
= ()
let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))))
(ensures (modifies_3_2 b b' h0 h1))
= ()
let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
(ensures (modifies_region rid bufs h0 h1))
= ()
(* Lemmas revealing the content of the specialized modifies clauses in order to
// be able to generalize them if needs be. *)
let lemma_reveal_modifies_0 h0 h1 : Lemma
(requires (modifies_0 h0 h1))
(ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_1 b h0 h1))
(ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma
(requires (modifies_2_1 b h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in
((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))))
= ()
let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) )))
= ()
let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma
(requires (modifies_3 b b' b'' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in
((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 )
\/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid''
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) )))
= ()
let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires (modifies_3_2 b b' h0 h1))
(ensures (
HS.get_tip h0 == HS.get_tip h1 /\
(let rid = frameOf b in let rid' = frameOf b' in
((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1)
\/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1
/\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1
/\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 )
\/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0
/\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1
/\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) )))
= ()
let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma
(requires (modifies_region rid bufs h0 h1))
(ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1))
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(* Stack effect specific lemmas *)
let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3))
(ensures (modifies_buf_1 (frameOf b) b h0 h3))
[SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma
(requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3))
(ensures (modifies_2 b b' h0 h3))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)]
= ()
(* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for
// verification as the specialized modifies clauses are abstract from outside the
// module *)
(** Commutativity lemmas *)
let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1))
[SMTPat (modifies_2 b b' h0 h1)]
= ()
let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma
(requires True)
(ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1))
[SMTPat (modifies_3_2 b b' h0 h1)]
= ()
(* TODO: add commutativity lemmas for modifies_3 *)
#reset-options "--z3rlimit 20"
(** Transitivity lemmas *)
let lemma_modifies_0_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)]
= ()
let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
(* TODO: Make the following work and merge with the following lemma *)
(* [SMTPatOr [ *)
(* [SMTPat (modifies_2 b b' h0 h1); *)
(* SMTPat (modifies_2 b' b h0 h1)]]; *)
(* SMTPat (modifies_2 b' b h1 h2)] *)
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 40"
let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma
(requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2))
(ensures (modifies_3 b b' b'' h0 h2))
(* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *)
[SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)]
= ()
#reset-options "--z3rlimit 200"
let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)]
= ()
#reset-options "--z3rlimit 20"
(* Specific modifies clause lemmas *)
val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma
(requires (modifies_0 h0 h1 /\ modifies_0 h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)]
let lemma_modifies_0_0 h0 h1 h2 = ()
#reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2))
(ensures (live h2 b /\ modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)]
= ()
let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
[SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
#reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
else ()
#reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0"
let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b'
/\ modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)]
= ()
let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_2 b' b h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)]
= ()
let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)]
= ()
let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma
(requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\
modifies_1 b' h1 h2))
(ensures (modifies_2_1 b h0 h2))
[SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b b' h0 h2))
[SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2))
(ensures (modifies_2 b' b h0 h2))
[SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)]
= ()
let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma
(requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2))
(ensures (modifies_3_2 b b' h0 h2))
[SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
= ()
(* TODO: lemmas for modifies_3 *)
let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (b `unused_in` h0 /\
frameOf b == HS.get_tip h0 /\
modifies_0 h0 h1 /\
modifies_1 b h1 h2))
(ensures (modifies_0 h0 h2))
= ()
let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma
(requires (modifies_none h0 h1 /\
live h0 b /\
modifies_1 b h1 h2))
(ensures (modifies_1 b h0 h2))
= ()
let lemma_modifies_0_none_trans h0 h1 h2 : Lemma
(requires (modifies_0 h0 h1 /\
modifies_none h1 h2))
(ensures (modifies_0 h0 h2))
= ()
#reset-options "--initial_fuel 0 --max_fuel 0"
(** Concrete getters and setters *)
val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a)
(requires (fun h -> True))
(ensures (fun (h0:mem) b h1 -> b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ frameOf b == HS.get_tip h0
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.create (v len) init))
let create #a init len =
let content: reference (lseq a (v len)) =
salloc (Seq.create (v len) init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
unfold let p (#a:Type0) (init:list a) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init <= UInt.max_int 32)
unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
(** Concrete getters and setters *)
val createL: #a:Type0 -> init:list a -> StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0:mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0
/\ b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == len
/\ frameOf b == (HS.get_tip h0)
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ modifies_0 h0 h1
/\ as_seq h1 b == Seq.seq_of_list init
/\ q #a len b))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
let content: reference (lseq a (v len)) =
salloc (Seq.seq_of_list init) in
let b = MkBuffer len content 0ul len in
let h = HST.get() in
assert (Seq.equal (as_seq h b) (sel h b));
b
#reset-options "--initial_fuel 0 --max_fuel 0"
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma
(requires True)
(ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
= let m = HS.get_hmap h in
let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in
Set.lemma_equal_intro (Map.domain m) (Map.domain m')
unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0
= b `unused_in` h0
/\ live h1 b /\ idx b == 0 /\ length b == v len
/\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0)
/\ HS.get_tip h1 == HS.get_tip h0
/\ modifies (Set.singleton r) h0 h1
/\ modifies_ref r Set.empty h0 h1
/\ as_seq h1 b == Seq.create (v len) init
private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
is_mm b.content == mm))
= let h0 = HST.get() in
let s = Seq.create (v len) init in
let content: reference (lseq a (v len)) =
if mm then ralloc_mm r s else ralloc r s
in
let b = MkBuffer len content 0ul len in
let h1 = HST.get() in
assert (Seq.equal (as_seq h1 b) (sel h1 b));
lemma_upd h0 content s;
b
(** This function allocates a buffer in an "eternal" region, i.e. a region where memory is
// * automatically-managed. One does not need to call rfree on such a buffer. It
// * translates to C as a call to malloc and assumes a conservative garbage
// * collector is running. *)
val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a)
(requires (fun h -> is_eternal_region r))
(ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content)))
let rcreate #a r init len = rcreate_common r init len false
(** This predicate tells whether a buffer can be `rfree`d. The only
way to produce it should be `rcreate_mm`, and the only way to
consume it should be `rfree.` Rationale: a buffer can be `rfree`d
only if it is the result of `rcreate_mm`. Subbuffers should not. *)
let freeable (#a: Type) (b: buffer a) : GTot Type0 =
is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0
(** This function allocates a buffer into a manually-managed buffer in a heap
* region, meaning that the client must call rfree in order to avoid memory
* leaks. It translates to C as a straight malloc. *)
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t)
:ST (buffer a) (requires (fun h0 -> is_eternal_region r))
(ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
= rcreate_common r init len true
#reset-options
(** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *)
let rfree (#a:Type) (b:buffer a)
:ST unit (requires (fun h0 -> live h0 b /\ freeable b))
(ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
= rfree b.content
(* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *)
(* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *)
(* (requires (fun h -> True)) *)
(* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *)
(* let create_null #a init len = *)
(* push_frame(); *)
(* let r = create init len in *)
(* pop_frame(); *)
(* r *)
#reset-options "--initial_fuel 0 --max_fuel 0"
// ocaml-only, used for conversions to Platform.bytes
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
(*/\ r == as_seq #a h1 b *) ))
let to_seq #a b l =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v l)
// ocaml-only, used for conversions to Platform.bytes
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a)
(requires (fun h -> live h b))
(ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
r == as_seq #a h1 b ))
let to_seq_full #a b =
let s = !b.content in
let i = v b.idx in
Seq.slice s i (i + v b.length)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let index #a b n =
let s = !b.content in
Seq.index s (v b.idx + v n)
(** REMARK: the proof of this lemma relies crucially on the `a == a'` condition
// in `disjoint`, and on the pattern in `Seq.slice_upd` *)
private let lemma_aux_0
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt)
:Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb))
(ensures (live h0 b /\ live h0 bb /\
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb)))
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ()
#set-options "--z3rlimit 10"
private let lemma_aux_1
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
#reset-options "--initial_fuel 0 --max_fuel 0"
private let lemma_aux_2
(#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem)
:Lemma (requires (live h0 b))
(ensures (live h0 b /\
(forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==>
(let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
as_seq h0 bb == as_seq h1 bb))))
= let open FStar.Classical in
forall_intro (move_requires (lemma_aux_1 b n z h0))
private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a
-> h0:mem -> Lemma
(requires (live h0 b))
(ensures (live h0 b
/\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
[SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let upd #a b n z =
let h0 = HST.get () in
let s0 = !b.content in
let s = Seq.upd s0 (v b.idx + v n) z in
b.content := s;
lemma_aux b n z h0;
let h = HST.get() in
Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b));
Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val sub: #a:Type -> b:buffer a -> i:UInt32.t
-> len:UInt32.t{v i + v len <= length b}
-> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
let sub #a b i len =
assert (v i + v b.idx < pow2 n); // was formerly a precondition
MkBuffer b.max_length b.content (i +^ b.idx) len
let sub_sub
(#a: Type)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t{v i1 + v len1 <= length b})
(i2: UInt32.t)
(len2: UInt32.t {v i2 + v len2 <= v len1})
: Lemma
(ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2))
= ()
let sub_zero_length
(#a: Type)
(b: buffer a)
: Lemma
(ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (sub b i len); SMTPat (live h b)]
= Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
let lemma_sub_spec' (#a:Type) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t{v len <= length b /\ v i + v len <= length b})
h : Lemma
(requires (live h b))
(ensures (live h (sub b i len) /\
as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
[SMTPat (live h (sub b i len))]
= lemma_sub_spec b i len h
val offset: #a:Type -> b:buffer a
-> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}
-> Tot (b':buffer a{b `includes` b'})
let offset #a b i =
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
let lemma_offset_spec (#a:Type) (b:buffer a)
(i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length})
h : Lemma
(requires True)
(ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b)))
[SMTPatOr [[SMTPat (as_seq h (offset b i))];
[SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]]
= Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b))
private val eq_lemma1:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
(ensures equal h (sub b1 0ul len) h (sub b2 0ul len))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma1 #a b1 b2 len h =
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
#reset-options "--z3rlimit 20"
private val eq_lemma2:
#a:eqtype
-> b1:buffer a
-> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> h:mem
-> Lemma
(requires equal h (sub b1 0ul len) h (sub b2 0ul len))
(ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
[SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
let eq_lemma2 #a b1 b2 len h =
let s1 = as_seq h (sub b1 0ul len) in
let s2 = as_seq h (sub b2 0ul len) in
cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j);
cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
(** Corresponds to memcmp for `eqtype` *)
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a
-> len:UInt32.t{v len <= length b1 /\ v len <= length b2}
-> ST bool
(requires (fun h -> live h b1 /\ live h b2))
(ensures (fun h0 z h1 -> h1 == h0 /\
(z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
let rec eqb #a b1 b2 len =
if len =^ 0ul then true
else
let len' = len -^ 1ul in
if index b1 len' = index b2 len' then
eqb b1 b2 len'
else
false
(**
// Defining operators for buffer accesses as specified at
// https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence
// *)
(* JP: if the [val] is not specified, there's an issue with these functions
// * taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a
(requires (fun h -> live h b))
(ensures (fun h0 z h1 -> h1 == h0
/\ z == Seq.index (as_seq h0 b) (v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit
(requires (fun h -> live h b /\ v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b
/\ modifies_1 b h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma
(requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2))
(ensures (modifies_one (frameOf b) h0 h2))
[SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)]
= ()
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0"
(** Corresponds to memcpy *)
val blit: #t:Type
-> a:buffer t
-> idx_a:UInt32.t{v idx_a <= length a}
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t{v idx_b <= length b}
-> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b}
-> Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1
/\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) ==
Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len)
/\ Seq.slice (as_seq h1 b) 0 (v idx_b) ==
Seq.slice (as_seq h0 b) 0 (v idx_b)
/\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) == | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.TSet.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int32.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Buffer.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int32",
"short_module": "Int32"
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: FStar.Buffer.buffer t ->
idx_a: FStar.UInt32.t{FStar.UInt32.v idx_a <= FStar.Buffer.length a} ->
b: FStar.Buffer.buffer t {FStar.Buffer.disjoint a b} ->
idx_b: FStar.UInt32.t{FStar.UInt32.v idx_b <= FStar.Buffer.length b} ->
len:
FStar.UInt32.t
{ FStar.UInt32.v idx_a + FStar.UInt32.v len <= FStar.Buffer.length a /\
FStar.UInt32.v idx_b + FStar.UInt32.v len <= FStar.Buffer.length b }
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Buffer.disjoint",
"Prims.l_and",
"Prims.op_Addition",
"FStar.UInt32.op_Equals_Hat",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Prims.bool",
"FStar.Seq.Properties.cons_head_tail",
"FStar.Seq.Base.slice",
"FStar.Buffer.as_seq",
"FStar.Seq.Properties.snoc_slice_index",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Buffer.op_Array_Assignment",
"FStar.UInt32.op_Plus_Hat",
"FStar.Buffer.op_Array_Access",
"FStar.Buffer.blit",
"FStar.UInt32.op_Subtraction_Hat"
] | [
"recursion"
] | false | true | false | false | false | let rec blit #t a idx_a b idx_b len =
| let h0 = HST.get () in
if len =^ 0ul
then ()
else
let len' = len -^ 1ul in
blit #t a idx_a b idx_b len';
let z = a.(idx_a +^ len') in
b.(idx_b +^ len') <- z;
let h1 = HST.get () in
Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len');
Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b));
Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b)) | false |
Pulse.C.Types.Struct.fsti | Pulse.C.Types.Struct.struct_field | val struct_field:
#tn: Type0 ->
#tf: Type0 ->
#n: string ->
#fields: nonempty_field_description_t tf ->
#v: Ghost.erased (struct_t0 tn n fields) ->
r: ref (struct0 tn n fields) ->
field: field_t fields ->
#t': Type0 ->
#td': typedef t' ->
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field)) ->
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field)) ->
Prims.unit
-> stt (ref td')
(pts_to r v)
(fun r' ->
(pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) **
pts_to r' (struct_get_field v field)) **
has_struct_field r field r') | val struct_field:
#tn: Type0 ->
#tf: Type0 ->
#n: string ->
#fields: nonempty_field_description_t tf ->
#v: Ghost.erased (struct_t0 tn n fields) ->
r: ref (struct0 tn n fields) ->
field: field_t fields ->
#t': Type0 ->
#td': typedef t' ->
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field)) ->
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field)) ->
Prims.unit
-> stt (ref td')
(pts_to r v)
(fun r' ->
(pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) **
pts_to r' (struct_get_field v field)) **
has_struct_field r field r') | let struct_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(# [ norm_fields () ] sq_t': squash (t' == fields.fd_type field))
(# [ norm_fields () ] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td')
(pts_to r v)
(fun r' -> pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (struct_get_field v field) ** has_struct_field r field r')
= struct_field0
t'
r
field
td' | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Struct.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 291,
"start_col": 0,
"start_line": 271
} | module Pulse.C.Types.Struct
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
// To be extracted as: struct t { fields ... }
[@@noextract_to "krml"] // primitive
val define_struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_struct (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= define_struct0 tn #tf n fields
// To be extracted as: struct t
[@@noextract_to "krml"] // primitive
val struct_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let struct_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot Type0
= struct_t0 tn #tf n fields
val struct_set_field (#tn: Type0) (#tf: Type0) (#n: string) (#fields: nonempty_field_description_t tf) (f: field_t fields) (v: fields.fd_type f) (s: struct_t0 tn n fields) : GTot (struct_t0 tn n fields)
val struct_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
: GTot (fields.fd_type field)
val struct_eq
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s1 s2: struct_t0 tn n fields)
: Ghost prop
(requires True)
(ensures (fun y ->
(y <==> (s1 == s2)) /\
(y <==> (forall field . struct_get_field s1 field == struct_get_field s2 field))
))
val struct_get_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(struct_get_field (struct_set_field field v s) field == v)
[SMTPat (struct_get_field (struct_set_field field v s) field)]
val struct_get_field_other
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(requires (field' <> field))
(ensures (struct_get_field (struct_set_field field v s) field' == struct_get_field s field'))
let struct_get_field_pat
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(s: struct_t0 tn n fields)
(field: field_t fields)
(v: fields.fd_type field)
(field': field_t fields)
: Lemma
(struct_get_field (struct_set_field field v s) field' == (if field' = field then v else struct_get_field s field'))
[SMTPat (struct_get_field (struct_set_field field v s) field')]
= if field' = field
then ()
else struct_get_field_other s field v field'
[@@noextract_to "krml"] // proof-only
val struct0 (tn: Type0) (#tf: Type0) (n: string) (fields: nonempty_field_description_t tf) : Tot (typedef (struct_t0 tn n fields))
inline_for_extraction
[@@noextract_to "krml"; norm_field_attr] // proof-only
let struct (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: nonempty_field_description_t tf) : Tot (typedef (struct_t0 tn n fields))
= struct0 tn #tf n fields
val struct_get_field_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: nonempty_field_description_t tf)
(field: field_t fields)
: Lemma
(struct_get_field (unknown (struct0 tn n fields)) field == unknown (fields.fd_typedef field))
[SMTPat (struct_get_field (unknown (struct0 tn n fields)) field)]
val struct_get_field_uninitialized
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: nonempty_field_description_t tf)
(field: field_t fields)
: Lemma
(struct_get_field (uninitialized (struct0 tn n fields)) field == uninitialized (fields.fd_typedef field))
[SMTPat (struct_get_field (uninitialized (struct0 tn n fields)) field)]
val has_struct_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: Tot vprop
val has_struct_field_prop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_struct_field r field r')
(fun _ -> has_struct_field r field r' ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
val has_struct_field_dup
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_struct_field r field r')
(fun _ -> has_struct_field r field r' ** has_struct_field r field r')
val has_struct_field_inj
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t1: Type0)
(#td1: typedef t1)
(r1: ref td1)
(#t2: Type0)
(#td2: typedef t2)
(r2: ref td2)
: stt_ghost (squash (t1 == t2 /\ td1 == td2))
(has_struct_field r field r1 ** has_struct_field r field r2)
(fun _ -> has_struct_field r field r1 ** has_struct_field r field r2 ** ref_equiv r1 (coerce_eq () r2))
val has_struct_field_equiv_from
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r1: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
(r2: ref (struct0 tn n fields))
: stt_ghost unit
(ref_equiv r1 r2 ** has_struct_field r1 field r')
(fun _ -> ref_equiv r1 r2 ** has_struct_field r2 field r')
val has_struct_field_equiv_to
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r1' r2': ref td')
: stt_ghost unit
(ref_equiv r1' r2' ** has_struct_field r field r1')
(fun _ -> ref_equiv r1' r2' ** has_struct_field r field r2')
val ghost_struct_field_focus
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost (squash (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
(has_struct_field r field r' ** pts_to r v)
(fun _ -> has_struct_field r field r' ** pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (Ghost.hide (coerce_eq () (struct_get_field v field))))
val ghost_struct_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
: stt_ghost (Ghost.erased (ref (fields.fd_typedef field)))
(pts_to r v)
(fun r' -> pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (struct_get_field v field) ** has_struct_field r field r')
[@@noextract_to "krml"] // primitive
val struct_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td')
(pts_to r v)
(fun r' -> pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (Ghost.hide (coerce_eq () (struct_get_field v field))) ** has_struct_field r field r')
inline_for_extraction
[@@noextract_to "krml"] // primitive
let struct_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) ** pts_to r' (struct_get_field v field) ** has_struct_field r field r')
= struct_field0 t' r field td' | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Struct.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Struct.struct0 tn n fields) ->
field: Pulse.C.Types.Fields.field_t fields ->
_: Prims.unit
-> Pulse.Lib.Core.stt (Pulse.C.Types.Base.ref td')
(Pulse.C.Types.Base.pts_to r v)
(fun r' ->
(Pulse.C.Types.Base.pts_to r
(FStar.Ghost.hide (Pulse.C.Types.Struct.struct_set_field field
(Pulse.C.Types.Base.unknown (Mkfield_description_t?.fd_typedef fields field))
(FStar.Ghost.reveal v))) **
Pulse.C.Types.Base.pts_to r'
(FStar.Ghost.hide (Pulse.C.Types.Struct.struct_get_field (FStar.Ghost.reveal v) field))) **
Pulse.C.Types.Struct.has_struct_field r field r') | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Pulse.C.Types.Fields.nonempty_field_description_t",
"FStar.Ghost.erased",
"Pulse.C.Types.Struct.struct_t0",
"Pulse.C.Types.Base.ref",
"Pulse.C.Types.Struct.struct0",
"Pulse.C.Types.Fields.field_t",
"Pulse.C.Types.Base.typedef",
"Prims.squash",
"Prims.eq2",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef",
"Prims.unit",
"Pulse.C.Types.Struct.struct_field0",
"Pulse.Lib.Core.stt",
"Pulse.C.Types.Base.pts_to",
"Pulse.Lib.Core.op_Star_Star",
"FStar.Ghost.hide",
"Pulse.C.Types.Struct.struct_set_field",
"Pulse.C.Types.Base.unknown",
"FStar.Ghost.reveal",
"Pulse.C.Types.Struct.struct_get_field",
"Pulse.C.Types.Struct.has_struct_field",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let struct_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(#v: Ghost.erased (struct_t0 tn n fields))
(r: ref (struct0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field))
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td')
(pts_to r v)
(fun r' ->
(pts_to r (struct_set_field field (unknown (fields.fd_typedef field)) v) **
pts_to r' (struct_get_field v field)) **
has_struct_field r field r') =
| struct_field0 t' r field td' | false |
Hacl.Impl.Frodo.KEM.KeyGen.fst | Hacl.Impl.Frodo.KEM.KeyGen.clear_matrix2 | val clear_matrix2:
a:FP.frodo_alg
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h s_matrix /\ live h e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 ->
modifies (loc s_matrix |+| loc e_matrix) h0 h1) | val clear_matrix2:
a:FP.frodo_alg
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h s_matrix /\ live h e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 ->
modifies (loc s_matrix |+| loc e_matrix) h0 h1) | let clear_matrix2 a s_matrix e_matrix =
clear_matrix s_matrix;
clear_matrix e_matrix | {
"file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 147,
"start_col": 0,
"start_line": 145
} | module Hacl.Impl.Frodo.KEM.KeyGen
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
open Hacl.Impl.Frodo.KEM
open Hacl.Impl.Frodo.Pack
open Hacl.Impl.Frodo.Sample
open Hacl.Frodo.Random
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module M = Spec.Matrix
module FP = Spec.Frodo.Params
module S = Spec.Frodo.KEM.KeyGen
#set-options "--z3rlimit 100 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_shake_r:
a:FP.frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_t
-> r:lbytes output_len
-> Stack unit
(requires fun h ->
live h seed_se /\ live h r /\ disjoint seed_se r)
(ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\
as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len))
let frodo_shake_r a c seed_se output_len r =
push_frame ();
let h0 = ST.get () in
let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in
shake_input_seed_se.(0ul) <- c;
update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c);
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se);
LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se);
frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r;
clear_words_u8 shake_input_seed_se;
pop_frame ()
inline_for_extraction noextract
val frodo_mul_add_as_plus_e:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\
disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\
disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\
as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix =
FP.params_n_sqr a;
push_frame();
let a_matrix = matrix_create (params_n a) (params_n a) in
frodo_gen_matrix gen_a (params_n a) seed_a a_matrix;
matrix_mul_s a_matrix s_matrix b_matrix;
matrix_add b_matrix e_matrix;
pop_frame()
inline_for_extraction noextract
val frodo_mul_add_as_plus_e_pack:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b:lbytes (publicmatrixbytes_len a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h b /\
live h s_matrix /\ live h e_matrix /\
disjoint seed_a b /\ disjoint b s_matrix /\
disjoint b e_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b =
push_frame ();
let b_matrix = matrix_create (params_n a) params_nbar in
frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix;
frodo_pack (params_logq a) b_matrix b;
pop_frame ()
inline_for_extraction noextract
val get_s_e_matrices:
a:FP.frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_se /\ live h s_matrix /\ live h e_matrix /\
disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\
(as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se))
let get_s_e_matrices a seed_se s_matrix e_matrix =
push_frame ();
[@inline_let] let s_bytes_len = secretmatrixbytes_len a in
let r = create (2ul *! s_bytes_len) (u8 0) in
frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r;
frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix;
frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix;
pop_frame ()
inline_for_extraction noextract
val clear_matrix2:
a:FP.frodo_alg
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h s_matrix /\ live h e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 ->
modifies (loc s_matrix |+| loc e_matrix) h0 h1) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.KEM.KeyGen.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Sample.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"Hacl.Impl.Frodo.Pack.fst.checked",
"Hacl.Impl.Frodo.KEM.fst.checked",
"Hacl.Frodo.Random.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.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.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.KEM.KeyGen",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Frodo.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"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.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
a: Spec.Frodo.Params.frodo_alg ->
s_matrix:
Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a)
Hacl.Impl.Frodo.Params.params_nbar ->
e_matrix:
Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a)
Hacl.Impl.Frodo.Params.params_nbar
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Hacl.Impl.Matrix.matrix_t",
"Hacl.Impl.Frodo.Params.params_n",
"Hacl.Impl.Frodo.Params.params_nbar",
"Hacl.Impl.Frodo.KEM.clear_matrix",
"Prims.unit"
] | [] | false | true | false | false | false | let clear_matrix2 a s_matrix e_matrix =
| clear_matrix s_matrix;
clear_matrix e_matrix | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.proj_g_pow2_192_lemma | val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff) | val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff) | let proj_g_pow2_192_lemma () =
lemma_proj_g_pow2_192_eval ();
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_192_lemma S.mk_p256_concrete_ops S.base_point | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 165,
"start_col": 0,
"start_line": 161
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list
let proj_g_pow2_192_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list
val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff)
let proj_g_pow2_64_lemma () =
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_128_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff)
let proj_g_pow2_128_lemma () =
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_128_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
Spec.P256.PointOps.to_aff_point Hacl.P256.PrecompTable.proj_g_pow2_192 ==
Hacl.P256.PrecompTable.pow_point (Prims.pow2 192) Hacl.P256.PrecompTable.g_aff) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"Hacl.Spec.PrecompBaseTable256.a_pow2_192_lemma",
"Spec.P256.PointOps.proj_point",
"Spec.P256.mk_p256_concrete_ops",
"Spec.P256.PointOps.base_point",
"Hacl.P256.PrecompTable.lemma_proj_g_pow2_64_eval",
"Hacl.P256.PrecompTable.lemma_proj_g_pow2_128_eval",
"Hacl.P256.PrecompTable.lemma_proj_g_pow2_192_eval"
] | [] | true | false | true | false | false | let proj_g_pow2_192_lemma () =
| lemma_proj_g_pow2_192_eval ();
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_192_lemma S.mk_p256_concrete_ops S.base_point | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.proj_g_pow2_64_list | val proj_g_pow2_64_list:SPTK.point_list | val proj_g_pow2_64_list:SPTK.point_list | let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64) | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 117,
"start_col": 0,
"start_line": 116
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Spec.P256.PrecompTable.point_list | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize_term",
"Hacl.Spec.P256.PrecompTable.point_list",
"Hacl.Spec.P256.PrecompTable.proj_point_to_list",
"Hacl.P256.PrecompTable.proj_g_pow2_64"
] | [] | false | false | false | true | false | let proj_g_pow2_64_list:SPTK.point_list =
| normalize_term (SPTK.proj_point_to_list proj_g_pow2_64) | false |
Hacl.Impl.Frodo.KEM.KeyGen.fst | Hacl.Impl.Frodo.KEM.KeyGen.frodo_shake_r | val frodo_shake_r:
a:FP.frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_t
-> r:lbytes output_len
-> Stack unit
(requires fun h ->
live h seed_se /\ live h r /\ disjoint seed_se r)
(ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\
as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) | val frodo_shake_r:
a:FP.frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_t
-> r:lbytes output_len
-> Stack unit
(requires fun h ->
live h seed_se /\ live h r /\ disjoint seed_se r)
(ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\
as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) | let frodo_shake_r a c seed_se output_len r =
push_frame ();
let h0 = ST.get () in
let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in
shake_input_seed_se.(0ul) <- c;
update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c);
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se);
LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se);
frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r;
clear_words_u8 shake_input_seed_se;
pop_frame () | {
"file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 53,
"start_col": 0,
"start_line": 41
} | module Hacl.Impl.Frodo.KEM.KeyGen
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
open Hacl.Impl.Frodo.KEM
open Hacl.Impl.Frodo.Pack
open Hacl.Impl.Frodo.Sample
open Hacl.Frodo.Random
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module M = Spec.Matrix
module FP = Spec.Frodo.Params
module S = Spec.Frodo.KEM.KeyGen
#set-options "--z3rlimit 100 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_shake_r:
a:FP.frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_t
-> r:lbytes output_len
-> Stack unit
(requires fun h ->
live h seed_se /\ live h r /\ disjoint seed_se r)
(ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\
as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.KEM.KeyGen.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Sample.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"Hacl.Impl.Frodo.Pack.fst.checked",
"Hacl.Impl.Frodo.KEM.fst.checked",
"Hacl.Frodo.Random.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.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.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.KEM.KeyGen",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Frodo.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"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.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
a: Spec.Frodo.Params.frodo_alg ->
c: Lib.IntTypes.uint8 ->
seed_se: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) ->
output_len: Lib.IntTypes.size_t ->
r: Hacl.Impl.Matrix.lbytes output_len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.IntTypes.uint8",
"Hacl.Impl.Matrix.lbytes",
"Hacl.Impl.Frodo.Params.crypto_bytes",
"Lib.IntTypes.size_t",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Frodo.KEM.clear_words_u8",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Frodo.Params.frodo_shake",
"Lib.Sequence.eq_intro",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Lib.Sequence.concat",
"Lib.Sequence.create",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.Sequence.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.update_sub",
"Lib.Buffer.op_Array_Assignment",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.add",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let frodo_shake_r a c seed_se output_len r =
| push_frame ();
let h0 = ST.get () in
let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in
shake_input_seed_se.(0ul) <- c;
update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c);
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se);
LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se);
frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r;
clear_words_u8 shake_input_seed_se;
pop_frame () | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.proj_g_pow2_64_lemma | val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff) | val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff) | let proj_g_pow2_64_lemma () =
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_p256_concrete_ops S.base_point | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 146,
"start_col": 0,
"start_line": 144
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list
let proj_g_pow2_192_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list
val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
Spec.P256.PointOps.to_aff_point Hacl.P256.PrecompTable.proj_g_pow2_64 ==
Hacl.P256.PrecompTable.pow_point (Prims.pow2 64) Hacl.P256.PrecompTable.g_aff) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"Hacl.Spec.PrecompBaseTable256.a_pow2_64_lemma",
"Spec.P256.PointOps.proj_point",
"Spec.P256.mk_p256_concrete_ops",
"Spec.P256.PointOps.base_point",
"Hacl.P256.PrecompTable.lemma_proj_g_pow2_64_eval"
] | [] | true | false | true | false | false | let proj_g_pow2_64_lemma () =
| lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_p256_concrete_ops S.base_point | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.proj_g_pow2_192_lseq | val proj_g_pow2_192_lseq : LSeq.lseq uint64 12 | val proj_g_pow2_192_lseq : LSeq.lseq uint64 12 | let proj_g_pow2_192_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 138,
"start_col": 0,
"start_line": 136
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq Lib.IntTypes.uint64 12 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq_of_list",
"Lib.IntTypes.uint64",
"Hacl.P256.PrecompTable.proj_g_pow2_192_list",
"Prims.unit",
"FStar.Pervasives.normalize_term_spec",
"Hacl.Spec.P256.PrecompTable.point_list",
"Hacl.Spec.P256.PrecompTable.proj_point_to_list",
"Hacl.P256.PrecompTable.proj_g_pow2_192",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | false | let proj_g_pow2_192_lseq:LSeq.lseq uint64 12 =
| normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list | false |
Hacl.Impl.Frodo.KEM.KeyGen.fst | Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_keypair_ | val crypto_kem_keypair_:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h coins /\
disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk)
(ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\
(as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins)) | val crypto_kem_keypair_:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h coins /\
disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk)
(ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\
(as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins)) | let crypto_kem_keypair_ a gen_a coins pk sk =
FP.expand_crypto_secretkeybytes a;
FP.expand_crypto_secretkeybytes a;
let h0 = ST.get () in
let s = sub coins 0ul (crypto_bytes a) in
let seed_se = sub coins (crypto_bytes a) (crypto_bytes a) in
let z = sub coins (2ul *! crypto_bytes a) bytes_seed_a in
let seed_a = sub pk 0ul bytes_seed_a in
frodo_shake a bytes_seed_a z bytes_seed_a seed_a;
let b_bytes = sub pk bytes_seed_a (publicmatrixbytes_len a) in
let s_bytes = sub sk (crypto_bytes a +! crypto_publickeybytes a) (secretmatrixbytes_len a) in
frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b_bytes s_bytes;
let h1 = ST.get () in
LSeq.lemma_concat2 (v bytes_seed_a) (as_seq h1 seed_a) (v (publicmatrixbytes_len a)) (as_seq h1 b_bytes) (as_seq h1 pk);
crypto_kem_sk a s pk sk | {
"file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 280,
"start_col": 0,
"start_line": 263
} | module Hacl.Impl.Frodo.KEM.KeyGen
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
open Hacl.Impl.Frodo.KEM
open Hacl.Impl.Frodo.Pack
open Hacl.Impl.Frodo.Sample
open Hacl.Frodo.Random
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module M = Spec.Matrix
module FP = Spec.Frodo.Params
module S = Spec.Frodo.KEM.KeyGen
#set-options "--z3rlimit 100 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_shake_r:
a:FP.frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_t
-> r:lbytes output_len
-> Stack unit
(requires fun h ->
live h seed_se /\ live h r /\ disjoint seed_se r)
(ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\
as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len))
let frodo_shake_r a c seed_se output_len r =
push_frame ();
let h0 = ST.get () in
let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in
shake_input_seed_se.(0ul) <- c;
update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c);
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se);
LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se);
frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r;
clear_words_u8 shake_input_seed_se;
pop_frame ()
inline_for_extraction noextract
val frodo_mul_add_as_plus_e:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\
disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\
disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\
as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix =
FP.params_n_sqr a;
push_frame();
let a_matrix = matrix_create (params_n a) (params_n a) in
frodo_gen_matrix gen_a (params_n a) seed_a a_matrix;
matrix_mul_s a_matrix s_matrix b_matrix;
matrix_add b_matrix e_matrix;
pop_frame()
inline_for_extraction noextract
val frodo_mul_add_as_plus_e_pack:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b:lbytes (publicmatrixbytes_len a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h b /\
live h s_matrix /\ live h e_matrix /\
disjoint seed_a b /\ disjoint b s_matrix /\
disjoint b e_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b =
push_frame ();
let b_matrix = matrix_create (params_n a) params_nbar in
frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix;
frodo_pack (params_logq a) b_matrix b;
pop_frame ()
inline_for_extraction noextract
val get_s_e_matrices:
a:FP.frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_se /\ live h s_matrix /\ live h e_matrix /\
disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\
(as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se))
let get_s_e_matrices a seed_se s_matrix e_matrix =
push_frame ();
[@inline_let] let s_bytes_len = secretmatrixbytes_len a in
let r = create (2ul *! s_bytes_len) (u8 0) in
frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r;
frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix;
frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix;
pop_frame ()
inline_for_extraction noextract
val clear_matrix2:
a:FP.frodo_alg
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h s_matrix /\ live h e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 ->
modifies (loc s_matrix |+| loc e_matrix) h0 h1)
let clear_matrix2 a s_matrix e_matrix =
clear_matrix s_matrix;
clear_matrix e_matrix
inline_for_extraction noextract
val frodo_mul_add_as_plus_e_pack_shake:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> b:lbytes (publicmatrixbytes_len a)
-> s:lbytes (secretmatrixbytes_len a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h seed_se /\ live h s /\ live h b /\
disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\
disjoint seed_se b /\ disjoint seed_se s)
(ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\
(as_seq h1 b, as_seq h1 s) ==
S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se))
let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s =
push_frame ();
let s_matrix = matrix_create (params_n a) params_nbar in
let e_matrix = matrix_create (params_n a) params_nbar in
get_s_e_matrices a seed_se s_matrix e_matrix;
frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b;
matrix_to_lbytes s_matrix s;
clear_matrix2 a s_matrix e_matrix;
pop_frame ()
inline_for_extraction noextract
val crypto_kem_sk1:
a:FP.frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h s /\
disjoint pk sk /\ disjoint sk s)
(ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\
(let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in
as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes))
let crypto_kem_sk1 a s pk sk =
let h1 = ST.get () in
FP.expand_crypto_secretkeybytes a;
let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in
[@inline_let] let sm_len = secretmatrixbytes_len a in
let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in
let s_bytes = sub sk s_pk_len sm_len in
update_sub sk 0ul (crypto_bytes a) s;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes);
update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk;
let h3 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s);
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a))) (as_seq h1 pk);
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes);
LSeq.lemma_concat3
(v (crypto_bytes a)) (as_seq h1 s)
(v (crypto_publickeybytes a)) (as_seq h1 pk)
(v sm_len) (as_seq h1 s_bytes)
(as_seq h3 sk)
inline_for_extraction noextract
val crypto_kem_sk:
a:FP.frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h s /\
disjoint pk sk /\ disjoint sk s)
(ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\
(let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in
as_seq h1 sk == S.crypto_kem_sk a (as_seq h0 s) (as_seq h0 pk) s_bytes))
let crypto_kem_sk a s pk sk =
FP.expand_crypto_secretkeybytes a;
let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in
let sk_p = sub sk 0ul slen1 in
crypto_kem_sk1 a s pk sk_p;
let h0 = ST.get () in
update_sub_f h0 sk slen1 (bytes_pkhash a)
(fun h -> FP.frodo_shake a (v (crypto_publickeybytes a)) (as_seq h0 pk) (v (bytes_pkhash a)))
(fun _ -> frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) (sub sk slen1 (bytes_pkhash a)));
let h1 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (LSeq.sub (as_seq h1 sk) 0 (v slen1));
LSeq.lemma_concat2
(v slen1) (LSeq.sub (as_seq h0 sk) 0 (v slen1))
(v (bytes_pkhash a)) (LSeq.sub (as_seq h1 sk) (v slen1) (v (bytes_pkhash a))) (as_seq h1 sk)
inline_for_extraction noextract
val crypto_kem_keypair_:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h coins /\
disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk)
(ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\
(as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins)) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.KEM.KeyGen.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Sample.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"Hacl.Impl.Frodo.Pack.fst.checked",
"Hacl.Impl.Frodo.KEM.fst.checked",
"Hacl.Frodo.Random.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.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.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.KEM.KeyGen",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Frodo.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"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.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
a: Spec.Frodo.Params.frodo_alg ->
gen_a: Spec.Frodo.Params.frodo_gen_a{Hacl.Impl.Frodo.Params.is_supported gen_a} ->
coins:
Hacl.Impl.Matrix.lbytes (Lib.IntTypes.size 2 *! Hacl.Impl.Frodo.Params.crypto_bytes a +!
Hacl.Impl.Frodo.Params.bytes_seed_a) ->
pk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_publickeybytes a) ->
sk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_secretkeybytes a)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Spec.Frodo.Params.frodo_gen_a",
"Prims.b2t",
"Hacl.Impl.Frodo.Params.is_supported",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Hacl.Impl.Frodo.Params.crypto_bytes",
"Hacl.Impl.Frodo.Params.bytes_seed_a",
"Hacl.Impl.Frodo.Params.crypto_publickeybytes",
"Hacl.Impl.Frodo.Params.crypto_secretkeybytes",
"Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_sk",
"Prims.unit",
"Lib.Sequence.lemma_concat2",
"Lib.IntTypes.uint8",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Impl.Frodo.Params.publicmatrixbytes_len",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack_shake",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Hacl.Impl.Frodo.Params.secretmatrixbytes_len",
"Lib.Buffer.sub",
"Hacl.Impl.Frodo.Params.frodo_shake",
"FStar.UInt32.__uint_to_t",
"Spec.Frodo.Params.expand_crypto_secretkeybytes"
] | [] | false | true | false | false | false | let crypto_kem_keypair_ a gen_a coins pk sk =
| FP.expand_crypto_secretkeybytes a;
FP.expand_crypto_secretkeybytes a;
let h0 = ST.get () in
let s = sub coins 0ul (crypto_bytes a) in
let seed_se = sub coins (crypto_bytes a) (crypto_bytes a) in
let z = sub coins (2ul *! crypto_bytes a) bytes_seed_a in
let seed_a = sub pk 0ul bytes_seed_a in
frodo_shake a bytes_seed_a z bytes_seed_a seed_a;
let b_bytes = sub pk bytes_seed_a (publicmatrixbytes_len a) in
let s_bytes = sub sk (crypto_bytes a +! crypto_publickeybytes a) (secretmatrixbytes_len a) in
frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b_bytes s_bytes;
let h1 = ST.get () in
LSeq.lemma_concat2 (v bytes_seed_a)
(as_seq h1 seed_a)
(v (publicmatrixbytes_len a))
(as_seq h1 b_bytes)
(as_seq h1 pk);
crypto_kem_sk a s pk sk | false |
Hacl.Impl.Frodo.KEM.KeyGen.fst | Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_sk1 | val crypto_kem_sk1:
a:FP.frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h s /\
disjoint pk sk /\ disjoint sk s)
(ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\
(let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in
as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes)) | val crypto_kem_sk1:
a:FP.frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h s /\
disjoint pk sk /\ disjoint sk s)
(ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\
(let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in
as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes)) | let crypto_kem_sk1 a s pk sk =
let h1 = ST.get () in
FP.expand_crypto_secretkeybytes a;
let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in
[@inline_let] let sm_len = secretmatrixbytes_len a in
let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in
let s_bytes = sub sk s_pk_len sm_len in
update_sub sk 0ul (crypto_bytes a) s;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes);
update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk;
let h3 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s);
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a))) (as_seq h1 pk);
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes);
LSeq.lemma_concat3
(v (crypto_bytes a)) (as_seq h1 s)
(v (crypto_publickeybytes a)) (as_seq h1 pk)
(v sm_len) (as_seq h1 s_bytes)
(as_seq h3 sk) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 215,
"start_col": 0,
"start_line": 194
} | module Hacl.Impl.Frodo.KEM.KeyGen
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
open Hacl.Impl.Frodo.KEM
open Hacl.Impl.Frodo.Pack
open Hacl.Impl.Frodo.Sample
open Hacl.Frodo.Random
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module M = Spec.Matrix
module FP = Spec.Frodo.Params
module S = Spec.Frodo.KEM.KeyGen
#set-options "--z3rlimit 100 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_shake_r:
a:FP.frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_t
-> r:lbytes output_len
-> Stack unit
(requires fun h ->
live h seed_se /\ live h r /\ disjoint seed_se r)
(ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\
as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len))
let frodo_shake_r a c seed_se output_len r =
push_frame ();
let h0 = ST.get () in
let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in
shake_input_seed_se.(0ul) <- c;
update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c);
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se);
LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se);
frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r;
clear_words_u8 shake_input_seed_se;
pop_frame ()
inline_for_extraction noextract
val frodo_mul_add_as_plus_e:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\
disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\
disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\
as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix =
FP.params_n_sqr a;
push_frame();
let a_matrix = matrix_create (params_n a) (params_n a) in
frodo_gen_matrix gen_a (params_n a) seed_a a_matrix;
matrix_mul_s a_matrix s_matrix b_matrix;
matrix_add b_matrix e_matrix;
pop_frame()
inline_for_extraction noextract
val frodo_mul_add_as_plus_e_pack:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b:lbytes (publicmatrixbytes_len a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h b /\
live h s_matrix /\ live h e_matrix /\
disjoint seed_a b /\ disjoint b s_matrix /\
disjoint b e_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b =
push_frame ();
let b_matrix = matrix_create (params_n a) params_nbar in
frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix;
frodo_pack (params_logq a) b_matrix b;
pop_frame ()
inline_for_extraction noextract
val get_s_e_matrices:
a:FP.frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_se /\ live h s_matrix /\ live h e_matrix /\
disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\
(as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se))
let get_s_e_matrices a seed_se s_matrix e_matrix =
push_frame ();
[@inline_let] let s_bytes_len = secretmatrixbytes_len a in
let r = create (2ul *! s_bytes_len) (u8 0) in
frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r;
frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix;
frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix;
pop_frame ()
inline_for_extraction noextract
val clear_matrix2:
a:FP.frodo_alg
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h s_matrix /\ live h e_matrix /\
disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 ->
modifies (loc s_matrix |+| loc e_matrix) h0 h1)
let clear_matrix2 a s_matrix e_matrix =
clear_matrix s_matrix;
clear_matrix e_matrix
inline_for_extraction noextract
val frodo_mul_add_as_plus_e_pack_shake:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> b:lbytes (publicmatrixbytes_len a)
-> s:lbytes (secretmatrixbytes_len a)
-> Stack unit
(requires fun h ->
live h seed_a /\ live h seed_se /\ live h s /\ live h b /\
disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\
disjoint seed_se b /\ disjoint seed_se s)
(ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\
(as_seq h1 b, as_seq h1 s) ==
S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se))
let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s =
push_frame ();
let s_matrix = matrix_create (params_n a) params_nbar in
let e_matrix = matrix_create (params_n a) params_nbar in
get_s_e_matrices a seed_se s_matrix e_matrix;
frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b;
matrix_to_lbytes s_matrix s;
clear_matrix2 a s_matrix e_matrix;
pop_frame ()
inline_for_extraction noextract
val crypto_kem_sk1:
a:FP.frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a)
-> Stack unit
(requires fun h ->
live h pk /\ live h sk /\ live h s /\
disjoint pk sk /\ disjoint sk s)
(ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\
(let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in
as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes)) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.KEM.KeyGen.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Sample.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"Hacl.Impl.Frodo.Pack.fst.checked",
"Hacl.Impl.Frodo.KEM.fst.checked",
"Hacl.Frodo.Random.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.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.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.KEM.KeyGen",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Frodo.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"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.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
a: Spec.Frodo.Params.frodo_alg ->
s: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) ->
pk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_publickeybytes a) ->
sk:
Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_secretkeybytes a -!
Hacl.Impl.Frodo.Params.bytes_pkhash a)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Hacl.Impl.Matrix.lbytes",
"Hacl.Impl.Frodo.Params.crypto_bytes",
"Hacl.Impl.Frodo.Params.crypto_publickeybytes",
"Lib.IntTypes.op_Subtraction_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Frodo.Params.crypto_secretkeybytes",
"Hacl.Impl.Frodo.Params.bytes_pkhash",
"Lib.Sequence.lemma_concat3",
"Lib.IntTypes.uint8",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Lib.Sequence.eq_intro",
"Lib.Sequence.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.update_sub",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.sub",
"Hacl.Impl.Frodo.Params.secretmatrixbytes_len",
"Lib.IntTypes.op_Plus_Bang",
"Spec.Frodo.Params.expand_crypto_secretkeybytes"
] | [] | false | true | false | false | false | let crypto_kem_sk1 a s pk sk =
| let h1 = ST.get () in
FP.expand_crypto_secretkeybytes a;
let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in
[@@ inline_let ]let sm_len = secretmatrixbytes_len a in
let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in
let s_bytes = sub sk s_pk_len sm_len in
update_sub sk 0ul (crypto_bytes a) s;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes);
update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk;
let h3 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s);
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a)))
(as_seq h1 pk);
LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes);
LSeq.lemma_concat3 (v (crypto_bytes a))
(as_seq h1 s)
(v (crypto_publickeybytes a))
(as_seq h1 pk)
(v sm_len)
(as_seq h1 s_bytes)
(as_seq h3 sk) | false |
Hacl.Impl.Frodo.KEM.KeyGen.fst | Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e | val frodo_mul_add_as_plus_e:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\
disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\
disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\
as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) | val frodo_mul_add_as_plus_e:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\
disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\
disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\
as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) | let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix =
FP.params_n_sqr a;
push_frame();
let a_matrix = matrix_create (params_n a) (params_n a) in
frodo_gen_matrix gen_a (params_n a) seed_a a_matrix;
matrix_mul_s a_matrix s_matrix b_matrix;
matrix_add b_matrix e_matrix;
pop_frame() | {
"file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 80,
"start_col": 0,
"start_line": 73
} | module Hacl.Impl.Frodo.KEM.KeyGen
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open LowStar.Buffer
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
open Hacl.Impl.Frodo.KEM
open Hacl.Impl.Frodo.Pack
open Hacl.Impl.Frodo.Sample
open Hacl.Frodo.Random
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module M = Spec.Matrix
module FP = Spec.Frodo.Params
module S = Spec.Frodo.KEM.KeyGen
#set-options "--z3rlimit 100 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_shake_r:
a:FP.frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_t
-> r:lbytes output_len
-> Stack unit
(requires fun h ->
live h seed_se /\ live h r /\ disjoint seed_se r)
(ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\
as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len))
let frodo_shake_r a c seed_se output_len r =
push_frame ();
let h0 = ST.get () in
let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in
shake_input_seed_se.(0ul) <- c;
update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se;
let h2 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c);
LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se);
LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se);
frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r;
clear_words_u8 shake_input_seed_se;
pop_frame ()
inline_for_extraction noextract
val frodo_mul_add_as_plus_e:
a:FP.frodo_alg
-> gen_a:FP.frodo_gen_a{is_supported gen_a}
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix_t (params_n a) params_nbar
-> e_matrix:matrix_t (params_n a) params_nbar
-> b_matrix:matrix_t (params_n a) params_nbar
-> Stack unit
(requires fun h ->
live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\
disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\
disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix)
(ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\
as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a)
(as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.KEM.KeyGen.fst.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Sample.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"Hacl.Impl.Frodo.Pack.fst.checked",
"Hacl.Impl.Frodo.KEM.fst.checked",
"Hacl.Frodo.Random.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.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.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.KEM.KeyGen",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Frodo.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"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.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
a: Spec.Frodo.Params.frodo_alg ->
gen_a: Spec.Frodo.Params.frodo_gen_a{Hacl.Impl.Frodo.Params.is_supported gen_a} ->
seed_a: Hacl.Impl.Matrix.lbytes Hacl.Impl.Frodo.Params.bytes_seed_a ->
s_matrix:
Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a)
Hacl.Impl.Frodo.Params.params_nbar ->
e_matrix:
Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a)
Hacl.Impl.Frodo.Params.params_nbar ->
b_matrix:
Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a)
Hacl.Impl.Frodo.Params.params_nbar
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Spec.Frodo.Params.frodo_gen_a",
"Prims.b2t",
"Hacl.Impl.Frodo.Params.is_supported",
"Hacl.Impl.Matrix.lbytes",
"Hacl.Impl.Frodo.Params.bytes_seed_a",
"Hacl.Impl.Matrix.matrix_t",
"Hacl.Impl.Frodo.Params.params_n",
"Hacl.Impl.Frodo.Params.params_nbar",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Matrix.matrix_add",
"Hacl.Impl.Matrix.matrix_mul_s",
"Hacl.Impl.Frodo.Params.frodo_gen_matrix",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Lib.IntTypes.mul",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Matrix.matrix_create",
"FStar.HyperStack.ST.push_frame",
"Spec.Frodo.Params.params_n_sqr"
] | [] | false | true | false | false | false | let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix =
| FP.params_n_sqr a;
push_frame ();
let a_matrix = matrix_create (params_n a) (params_n a) in
frodo_gen_matrix gen_a (params_n a) seed_a a_matrix;
matrix_mul_s a_matrix s_matrix b_matrix;
matrix_add b_matrix e_matrix;
pop_frame () | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.