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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PulseCore.Preorder.fst | PulseCore.Preorder.flip | val flip (#a: Type u#a) (p: preorder a) : preorder a | val flip (#a: Type u#a) (p: preorder a) : preorder a | let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 239,
"start_col": 0,
"start_line": 239
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= () | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.Preorder.preorder a -> FStar.Preorder.preorder a | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder"
] | [] | false | false | false | true | false | let flip (#a: Type u#a) (p: preorder a) : preorder a =
| fun x y -> p y x | false |
PulseCore.Preorder.fst | PulseCore.Preorder.hval_tot | val hval_tot (#a #p: _) (h: history a p {Current? h}) : a | val hval_tot (#a #p: _) (h: history a p {Current? h}) : a | let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 27,
"end_line": 287,
"start_col": 0,
"start_line": 285
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | h: PulseCore.Preorder.history a p {Current? h} -> a | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"Prims.b2t",
"PulseCore.Preorder.uu___is_Current",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"PulseCore.Preorder.curval"
] | [] | false | false | false | false | false | let hval_tot #a #p (h: history a p {Current? h}) : a =
| match h with | Current h _ -> curval h | false |
PulseCore.Preorder.fst | PulseCore.Preorder.extend_history | val extend_history (#a: Type u#a) (#q: preorder a) (h0: vhist q) (v: a{q (curval h0) v})
: h1: vhist q {h1 `extends` h0} | val extend_history (#a: Type u#a) (#q: preorder a) (h0: vhist q) (v: a{q (curval h0) v})
: h1: vhist q {h1 `extends` h0} | let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0 | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 11,
"end_line": 264,
"start_col": 0,
"start_line": 262
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | h0: PulseCore.Preorder.vhist q -> v: a{q (PulseCore.Preorder.curval h0) v}
-> h1: PulseCore.Preorder.vhist q {PulseCore.Preorder.extends h1 h0} | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.vhist",
"PulseCore.Preorder.curval",
"Prims.Cons",
"PulseCore.Preorder.extends"
] | [] | false | false | false | false | false | let extend_history (#a: Type u#a) (#q: preorder a) (h0: vhist q) (v: a{q (curval h0) v})
: h1: vhist q {h1 `extends` h0} =
| v :: h0 | false |
PulseCore.Preorder.fst | PulseCore.Preorder.pcm_of_preorder_induces_extends | val pcm_of_preorder_induces_extends (#a: Type u#a) (q: preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends)) | val pcm_of_preorder_induces_extends (#a: Type u#a) (q: preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends)) | let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
() | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 259,
"start_col": 0,
"start_line": 252
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= () | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | q: FStar.Preorder.preorder a
-> FStar.Pervasives.Lemma
(ensures
PulseCore.Preorder.induces_preorder (PulseCore.Preorder.pcm_of_preorder q)
(PulseCore.Preorder.flip PulseCore.Preorder.extends)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.hist",
"FStar.PCM.frame_preserving_upd",
"PulseCore.Preorder.pcm_of_preorder",
"Prims.unit",
"FStar.PCM.compatible",
"Prims.squash",
"PulseCore.Preorder.extends",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"Prims._assert",
"FStar.PCM.composable",
"Prims.l_True",
"PulseCore.Preorder.induces_preorder",
"PulseCore.Preorder.flip"
] | [] | false | false | true | false | false | let pcm_of_preorder_induces_extends (#a: Type u#a) (q: preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends)) =
| let fp_full (x y: hist q) (f: frame_preserving_upd (pcm_of_preorder q) x y) (v: hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v) (ensures extends (f v) v) [SMTPat ()] =
assert (composable (pcm_of_preorder q) x v)
in
() | false |
PulseCore.Preorder.fst | PulseCore.Preorder.unit_history | val unit_history (#a #p: _) : history a p | val unit_history (#a #p: _) : history a p | let unit_history #a #p : history a p = Witnessed [] | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 51,
"end_line": 320,
"start_col": 0,
"start_line": 320
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1) | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | PulseCore.Preorder.history a p | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.Witnessed",
"Prims.Nil",
"PulseCore.Preorder.history"
] | [] | false | false | false | false | false | let unit_history #a #p : history a p =
| Witnessed [] | false |
PulseCore.Preorder.fst | PulseCore.Preorder.hperm | val hperm (#a #p: _) (h: history a p {Current? h}) : perm | val hperm (#a #p: _) (h: history a p {Current? h}) : perm | let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 294,
"start_col": 0,
"start_line": 292
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | h: PulseCore.Preorder.history a p {Current? h} -> PulseCore.FractionalPermission.perm | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"Prims.b2t",
"PulseCore.Preorder.uu___is_Current",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm"
] | [] | false | false | false | false | false | let hperm #a #p (h: history a p {Current? h}) : perm =
| match h with | Current _ f -> f | false |
PulseCore.Preorder.fst | PulseCore.Preorder.pcm_history_preorder | val pcm_history_preorder (#a #p: _) : preorder (history a p) | val pcm_history_preorder (#a #p: _) : preorder (history a p) | let pcm_history_preorder #a #p : preorder (history a p) =
fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ ->
vh1 `extends` vh0 | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 23,
"end_line": 374,
"start_col": 0,
"start_line": 367
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options
let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
} | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Preorder.preorder (PulseCore.Preorder.history a p) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"FStar.Pervasives.Native.Mktuple2",
"PulseCore.Preorder.hist",
"PulseCore.Preorder.extends",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm"
] | [] | false | false | false | false | false | let pcm_history_preorder #a #p : preorder (history a p) =
| fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ -> vh1 `extends` vh0 | false |
PulseCore.Preorder.fst | PulseCore.Preorder.pcm_of_preorder | val pcm_of_preorder (#a: Type u#a) (q: preorder a) : pcm (hist q) | val pcm_of_preorder (#a: Type u#a) (q: preorder a) : pcm (hist q) | let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
} | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 1,
"end_line": 202,
"start_col": 0,
"start_line": 195
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | q: FStar.Preorder.preorder a -> FStar.PCM.pcm (PulseCore.Preorder.hist q) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.PCM.Mkpcm",
"PulseCore.Preorder.hist",
"PulseCore.Preorder.p",
"PulseCore.Preorder.comm_op",
"Prims.l_and",
"FStar.PCM.__proj__Mkpcm'__item__composable",
"FStar.PCM.__proj__Mkpcm'__item__op",
"Prims.unit",
"Prims.l_True",
"Prims.prop",
"FStar.PCM.pcm"
] | [] | false | false | false | false | false | let pcm_of_preorder (#a: Type u#a) (q: preorder a) : pcm (hist q) =
| {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
} | false |
PulseCore.Preorder.fst | PulseCore.Preorder.lem_is_unit | val lem_is_unit (#a #p: _) (x: history a p)
: Lemma (history_composable x unit_history /\ history_compose x unit_history == x) | val lem_is_unit (#a #p: _) (x: history a p)
: Lemma (history_composable x unit_history /\ history_compose x unit_history == x) | let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h []) | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 33,
"end_line": 332,
"start_col": 0,
"start_line": 322
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed [] | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: PulseCore.Preorder.history a p
-> FStar.Pervasives.Lemma
(ensures
PulseCore.Preorder.history_composable x PulseCore.Preorder.unit_history /\
PulseCore.Preorder.history_compose x PulseCore.Preorder.unit_history == x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"PulseCore.Preorder.hist",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"Prims._assert",
"PulseCore.Preorder.extends",
"Prims.Nil",
"Prims.unit",
"Prims.l_not",
"Prims.eq2",
"Prims.list",
"Prims.l_Forall",
"PulseCore.Preorder.p_op",
"PulseCore.Preorder.p_composable",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"PulseCore.Preorder.history_composable",
"PulseCore.Preorder.unit_history",
"PulseCore.Preorder.history_compose",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lem_is_unit #a #p (x: history a p)
: Lemma (history_composable x unit_history /\ history_compose x unit_history == x) =
| match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h: hist p). p_composable p h []);
assert (forall (h: hist p). p_op p h [] == h);
assert (forall (h: vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h []) | false |
PulseCore.Preorder.fst | PulseCore.Preorder.extend_history' | val extend_history' (#a #p: _) (h0: history a p {Current? h0}) (v: a{p (hval h0) v}) : history a p | val extend_history' (#a #p: _) (h0: history a p {Current? h0}) (v: a{p (hval h0) v}) : history a p | let extend_history' #a #p (h0:history a p{Current? h0})
(v:a{p (hval h0) v})
: history a p
= let Current h f = h0 in
Current (v :: h) f | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 416,
"start_col": 0,
"start_line": 412
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options
let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
}
let pcm_history_preorder #a #p : preorder (history a p) =
fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ ->
vh1 `extends` vh0
#push-options "--z3rlimit_factor 8 --ifuel 1 --fuel 0 --warn_error -271"
let pcm_history_induces_preorder #a #p
: Lemma (induces_preorder (pcm_history #a #p)
(pcm_history_preorder #a #p))
= let aux (x y:history a p)
(f:frame_preserving_upd (pcm_history #a #p) x y)
(v:history a p)
: Lemma
(requires compatible (pcm_history #a #p) x v)
(ensures (pcm_history_preorder #a #p) v (f v))
[SMTPat ()]
= let pcm = pcm_history #a #p in
let v1 = f v in
match x, v, v1 with
| Witnessed _, Witnessed _, Witnessed _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Witnessed _ -> ()
| Witnessed _, Current _ _, Witnessed _ -> ()
| Witnessed _, Witnessed _, Current _ _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Current _ _ -> ()
| Witnessed _, Current _ _, Current _ _ -> ()
| Current hx _, Current hv _, Witnessed _
| Current hx _, Current hv _, Current _ _ ->
let frame = FStar.IndefiniteDescription.indefinite_description_ghost
(history a p) (fun frame -> composable pcm x frame /\ op pcm frame x == v) in
match frame with
| Current hf _ -> ()
| Witnessed hf ->
assert (extends hx hf);
assert (hx == hv);
assert (composable pcm x (Witnessed hv))
in
()
#pop-options | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
h0: PulseCore.Preorder.history a p {Current? h0} ->
v: a{p (FStar.Ghost.reveal (PulseCore.Preorder.hval h0)) v}
-> PulseCore.Preorder.history a p | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"Prims.b2t",
"PulseCore.Preorder.uu___is_Current",
"FStar.Ghost.reveal",
"PulseCore.Preorder.hval",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"PulseCore.Preorder.Current",
"Prims.Cons"
] | [] | false | false | false | false | false | let extend_history' #a #p (h0: history a p {Current? h0}) (v: a{p (hval h0) v}) : history a p =
| let Current h f = h0 in
Current (v :: h) f | false |
PulseCore.Preorder.fst | PulseCore.Preorder.history_composable | val history_composable (#a #p: _) : symrel (history a p) | val history_composable (#a #p: _) : symrel (history a p) | let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 307,
"start_col": 0,
"start_line": 296
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.PCM.symrel (PulseCore.Preorder.history a p) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"FStar.Pervasives.Native.Mktuple2",
"PulseCore.Preorder.hist",
"PulseCore.Preorder.p_composable",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"PulseCore.Preorder.extends",
"Prims.l_and",
"Prims.eq2",
"Prims.b2t",
"FStar.Real.op_Less_Equals_Dot",
"PulseCore.FractionalPermission.__proj__MkPerm__item__v",
"PulseCore.FractionalPermission.sum_perm",
"FStar.Real.one",
"Prims.prop",
"FStar.PCM.symrel"
] | [] | false | false | false | false | false | let history_composable #a #p : symrel (history a p) =
| fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 -> p_composable p h0 h1
| Witnessed h0, Current h1 f | Current h1 f, Witnessed h0 -> extends #a #p h1 h0
| Current h0 f0, Current h1 f1 -> h0 == h1 /\ (sum_perm f0 f1).v <=. one | false |
PulseCore.Preorder.fst | PulseCore.Preorder.history_compose | val history_compose (#a #p: _) (h0: history a p) (h1: history a p {history_composable h0 h1})
: history a p | val history_compose (#a #p: _) (h0: history a p) (h1: history a p {history_composable h0 h1})
: history a p | let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1) | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 33,
"end_line": 318,
"start_col": 0,
"start_line": 309
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
h0: PulseCore.Preorder.history a p ->
h1: PulseCore.Preorder.history a p {PulseCore.Preorder.history_composable h0 h1}
-> PulseCore.Preorder.history a p | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"PulseCore.Preorder.history_composable",
"FStar.Pervasives.Native.Mktuple2",
"PulseCore.Preorder.hist",
"PulseCore.Preorder.Witnessed",
"PulseCore.Preorder.p_op",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"PulseCore.Preorder.Current",
"PulseCore.FractionalPermission.sum_perm"
] | [] | false | false | false | false | false | let history_compose #a #p (h0: history a p) (h1: history a p {history_composable h0 h1})
: history a p =
| match h0, h1 with
| Witnessed h0, Witnessed h1 -> Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1 | Witnessed h1, Current h0 f -> Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 -> Current h0 (sum_perm f0 f1) | false |
PulseCore.Preorder.fst | PulseCore.Preorder.pcm_history | val pcm_history (#a #p: _) : pcm (history a p) | val pcm_history (#a #p: _) : pcm (history a p) | let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
} | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 1,
"end_line": 365,
"start_col": 0,
"start_line": 354
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.PCM.pcm (PulseCore.Preorder.history a p) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.PCM.Mkpcm",
"PulseCore.Preorder.history",
"FStar.PCM.Mkpcm'",
"PulseCore.Preorder.history_composable",
"PulseCore.Preorder.history_compose",
"PulseCore.Preorder.unit_history",
"FStar.PCM.__proj__Mkpcm'__item__composable",
"Prims.unit",
"PulseCore.Preorder.assoc_l",
"PulseCore.Preorder.assoc_r",
"PulseCore.Preorder.lem_is_unit",
"Prims.l_True",
"Prims.prop",
"FStar.PCM.pcm"
] | [] | false | false | false | false | false | let pcm_history #a #p : pcm (history a p) =
| {
p = { composable = history_composable; op = history_compose; one = unit_history };
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True)
} | false |
PulseCore.Preorder.fst | PulseCore.Preorder.history_val | val history_val (#a #p: _) (h: history a p) (v: Ghost.erased a) (f: perm) : prop | val history_val (#a #p: _) (h: history a p) (v: Ghost.erased a) (f: perm) : prop | let history_val #a #p (h:history a p) (v:Ghost.erased a) (f:perm)
: prop
= Current? h /\ hval h == v /\ hperm h == f /\ f.v <=. one | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 426,
"start_col": 0,
"start_line": 424
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options
let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
}
let pcm_history_preorder #a #p : preorder (history a p) =
fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ ->
vh1 `extends` vh0
#push-options "--z3rlimit_factor 8 --ifuel 1 --fuel 0 --warn_error -271"
let pcm_history_induces_preorder #a #p
: Lemma (induces_preorder (pcm_history #a #p)
(pcm_history_preorder #a #p))
= let aux (x y:history a p)
(f:frame_preserving_upd (pcm_history #a #p) x y)
(v:history a p)
: Lemma
(requires compatible (pcm_history #a #p) x v)
(ensures (pcm_history_preorder #a #p) v (f v))
[SMTPat ()]
= let pcm = pcm_history #a #p in
let v1 = f v in
match x, v, v1 with
| Witnessed _, Witnessed _, Witnessed _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Witnessed _ -> ()
| Witnessed _, Current _ _, Witnessed _ -> ()
| Witnessed _, Witnessed _, Current _ _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Current _ _ -> ()
| Witnessed _, Current _ _, Current _ _ -> ()
| Current hx _, Current hv _, Witnessed _
| Current hx _, Current hv _, Current _ _ ->
let frame = FStar.IndefiniteDescription.indefinite_description_ghost
(history a p) (fun frame -> composable pcm x frame /\ op pcm frame x == v) in
match frame with
| Current hf _ -> ()
| Witnessed hf ->
assert (extends hx hf);
assert (hx == hv);
assert (composable pcm x (Witnessed hv))
in
()
#pop-options
let extend_history' #a #p (h0:history a p{Current? h0})
(v:a{p (hval h0) v})
: history a p
= let Current h f = h0 in
Current (v :: h) f
let extend_history'_is_frame_preserving #a #p
(h0:history a p{Current? h0 /\ hperm h0 == full_perm})
(v:a{p (hval h0) v})
: Lemma (frame_preserving pcm_history h0 (extend_history' h0 v))
= () | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
h: PulseCore.Preorder.history a p ->
v: FStar.Ghost.erased a ->
f: PulseCore.FractionalPermission.perm
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"FStar.Ghost.erased",
"PulseCore.FractionalPermission.perm",
"Prims.l_and",
"Prims.b2t",
"PulseCore.Preorder.uu___is_Current",
"Prims.eq2",
"PulseCore.Preorder.hval",
"PulseCore.Preorder.hperm",
"FStar.Real.op_Less_Equals_Dot",
"PulseCore.FractionalPermission.__proj__MkPerm__item__v",
"FStar.Real.one",
"Prims.prop"
] | [] | false | false | false | false | true | let history_val #a #p (h: history a p) (v: Ghost.erased a) (f: perm) : prop =
| Current? h /\ hval h == v /\ hperm h == f /\ f.v <=. one | false |
PulseCore.Preorder.fst | PulseCore.Preorder.lift_fact_is_stable | val lift_fact_is_stable (#a #p: _) (f: property a {FStar.Preorder.stable f p})
: Lemma (FStar.Preorder.stable #(history a p) (lift_fact f) (preorder_of_pcm pcm_history)) | val lift_fact_is_stable (#a #p: _) (f: property a {FStar.Preorder.stable f p})
: Lemma (FStar.Preorder.stable #(history a p) (lift_fact f) (preorder_of_pcm pcm_history)) | let lift_fact_is_stable #a #p (f:property a{FStar.Preorder.stable f p})
: Lemma (FStar.Preorder.stable #(history a p)
(lift_fact f)
(preorder_of_pcm pcm_history))
= assert (FStar.Preorder.stable #(history a p) (lift_fact f) pcm_history_preorder);
pcm_history_induces_preorder #a #p;
stability #(history a p) (lift_fact f) pcm_history_preorder pcm_history | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 75,
"end_line": 453,
"start_col": 0,
"start_line": 447
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options
let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
}
let pcm_history_preorder #a #p : preorder (history a p) =
fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ ->
vh1 `extends` vh0
#push-options "--z3rlimit_factor 8 --ifuel 1 --fuel 0 --warn_error -271"
let pcm_history_induces_preorder #a #p
: Lemma (induces_preorder (pcm_history #a #p)
(pcm_history_preorder #a #p))
= let aux (x y:history a p)
(f:frame_preserving_upd (pcm_history #a #p) x y)
(v:history a p)
: Lemma
(requires compatible (pcm_history #a #p) x v)
(ensures (pcm_history_preorder #a #p) v (f v))
[SMTPat ()]
= let pcm = pcm_history #a #p in
let v1 = f v in
match x, v, v1 with
| Witnessed _, Witnessed _, Witnessed _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Witnessed _ -> ()
| Witnessed _, Current _ _, Witnessed _ -> ()
| Witnessed _, Witnessed _, Current _ _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Current _ _ -> ()
| Witnessed _, Current _ _, Current _ _ -> ()
| Current hx _, Current hv _, Witnessed _
| Current hx _, Current hv _, Current _ _ ->
let frame = FStar.IndefiniteDescription.indefinite_description_ghost
(history a p) (fun frame -> composable pcm x frame /\ op pcm frame x == v) in
match frame with
| Current hf _ -> ()
| Witnessed hf ->
assert (extends hx hf);
assert (hx == hv);
assert (composable pcm x (Witnessed hv))
in
()
#pop-options
let extend_history' #a #p (h0:history a p{Current? h0})
(v:a{p (hval h0) v})
: history a p
= let Current h f = h0 in
Current (v :: h) f
let extend_history'_is_frame_preserving #a #p
(h0:history a p{Current? h0 /\ hperm h0 == full_perm})
(v:a{p (hval h0) v})
: Lemma (frame_preserving pcm_history h0 (extend_history' h0 v))
= ()
let history_val #a #p (h:history a p) (v:Ghost.erased a) (f:perm)
: prop
= Current? h /\ hval h == v /\ hperm h == f /\ f.v <=. one
let split_current #a #p (h:history a p { Current? h /\ (Current?.f h).v <=. one })
: half:history a p {
Current? h /\
composable pcm_history half half /\
op pcm_history half half == h /\
Current?.h half == Current?.h h /\
history_val half (hval h) (Current?.f half)
}
= let Current v p = h in
assert_spinoff (sum_perm (half_perm p) (half_perm p) == p);
Current v (half_perm p)
let lift_fact #a #p (f:property a)
: property (history a p)
= fun history ->
match history with
| Witnessed h -> Cons? h /\ f (Cons?.hd h)
| Current h _ -> f (hval history) | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: PulseCore.Preorder.property a {FStar.Preorder.stable f p}
-> FStar.Pervasives.Lemma
(ensures
FStar.Preorder.stable (PulseCore.Preorder.lift_fact f)
(PulseCore.Preorder.preorder_of_pcm PulseCore.Preorder.pcm_history)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.relation",
"FStar.Preorder.preorder_rel",
"PulseCore.Preorder.property",
"FStar.Preorder.stable",
"PulseCore.Preorder.stability",
"PulseCore.Preorder.history",
"PulseCore.Preorder.lift_fact",
"PulseCore.Preorder.pcm_history_preorder",
"PulseCore.Preorder.pcm_history",
"Prims.unit",
"PulseCore.Preorder.pcm_history_induces_preorder",
"Prims._assert",
"Prims.l_True",
"Prims.squash",
"PulseCore.Preorder.preorder_of_pcm",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lift_fact_is_stable #a #p (f: property a {FStar.Preorder.stable f p})
: Lemma (FStar.Preorder.stable #(history a p) (lift_fact f) (preorder_of_pcm pcm_history)) =
| assert (FStar.Preorder.stable #(history a p) (lift_fact f) pcm_history_preorder);
pcm_history_induces_preorder #a #p;
stability #(history a p) (lift_fact f) pcm_history_preorder pcm_history | false |
PulseCore.Preorder.fst | PulseCore.Preorder.lift_fact | val lift_fact (#a #p: _) (f: property a) : property (history a p) | val lift_fact (#a #p: _) (f: property a) : property (history a p) | let lift_fact #a #p (f:property a)
: property (history a p)
= fun history ->
match history with
| Witnessed h -> Cons? h /\ f (Cons?.hd h)
| Current h _ -> f (hval history) | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 39,
"end_line": 445,
"start_col": 0,
"start_line": 440
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options
let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
}
let pcm_history_preorder #a #p : preorder (history a p) =
fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ ->
vh1 `extends` vh0
#push-options "--z3rlimit_factor 8 --ifuel 1 --fuel 0 --warn_error -271"
let pcm_history_induces_preorder #a #p
: Lemma (induces_preorder (pcm_history #a #p)
(pcm_history_preorder #a #p))
= let aux (x y:history a p)
(f:frame_preserving_upd (pcm_history #a #p) x y)
(v:history a p)
: Lemma
(requires compatible (pcm_history #a #p) x v)
(ensures (pcm_history_preorder #a #p) v (f v))
[SMTPat ()]
= let pcm = pcm_history #a #p in
let v1 = f v in
match x, v, v1 with
| Witnessed _, Witnessed _, Witnessed _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Witnessed _ -> ()
| Witnessed _, Current _ _, Witnessed _ -> ()
| Witnessed _, Witnessed _, Current _ _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Current _ _ -> ()
| Witnessed _, Current _ _, Current _ _ -> ()
| Current hx _, Current hv _, Witnessed _
| Current hx _, Current hv _, Current _ _ ->
let frame = FStar.IndefiniteDescription.indefinite_description_ghost
(history a p) (fun frame -> composable pcm x frame /\ op pcm frame x == v) in
match frame with
| Current hf _ -> ()
| Witnessed hf ->
assert (extends hx hf);
assert (hx == hv);
assert (composable pcm x (Witnessed hv))
in
()
#pop-options
let extend_history' #a #p (h0:history a p{Current? h0})
(v:a{p (hval h0) v})
: history a p
= let Current h f = h0 in
Current (v :: h) f
let extend_history'_is_frame_preserving #a #p
(h0:history a p{Current? h0 /\ hperm h0 == full_perm})
(v:a{p (hval h0) v})
: Lemma (frame_preserving pcm_history h0 (extend_history' h0 v))
= ()
let history_val #a #p (h:history a p) (v:Ghost.erased a) (f:perm)
: prop
= Current? h /\ hval h == v /\ hperm h == f /\ f.v <=. one
let split_current #a #p (h:history a p { Current? h /\ (Current?.f h).v <=. one })
: half:history a p {
Current? h /\
composable pcm_history half half /\
op pcm_history half half == h /\
Current?.h half == Current?.h h /\
history_val half (hval h) (Current?.f half)
}
= let Current v p = h in
assert_spinoff (sum_perm (half_perm p) (half_perm p) == p);
Current v (half_perm p) | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: PulseCore.Preorder.property a -> PulseCore.Preorder.property (PulseCore.Preorder.history a p) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.property",
"PulseCore.Preorder.history",
"PulseCore.Preorder.hist",
"Prims.l_and",
"Prims.b2t",
"Prims.uu___is_Cons",
"Prims.__proj__Cons__item__hd",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"FStar.Ghost.reveal",
"PulseCore.Preorder.hval",
"Prims.prop"
] | [] | false | false | false | false | false | let lift_fact #a #p (f: property a) : property (history a p) =
| function
| Witnessed h -> Cons? h /\ f (Cons?.hd h)
| Current h _ -> f (hval history) | false |
Pulse.Lib.InvList.fsti | Pulse.Lib.InvList.invlist_names | val invlist_names (is: invlist0) : inames | val invlist_names (is: invlist0) : inames | let rec invlist_names (is : invlist0) : inames =
match is with
| [] -> emp_inames
| i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i) | {
"file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 67,
"end_line": 11,
"start_col": 0,
"start_line": 8
} | module Pulse.Lib.InvList
open Pulse.Lib.Pervasives
let invlist_elem = p:vprop & inv p
let invlist0 = list invlist_elem | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Priv.Trade0.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.InvList.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | is: Pulse.Lib.InvList.invlist0 -> Pulse.Lib.Core.inames | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.InvList.invlist0",
"Pulse.Lib.Core.emp_inames",
"Pulse.Lib.InvList.invlist_elem",
"Prims.list",
"Pulse.Lib.Core.add_iname",
"Pulse.Lib.InvList.invlist_names",
"Pulse.Lib.Core.name_of_inv",
"Prims.__proj__Mkdtuple2__item___1",
"Pulse.Lib.Core.vprop",
"Pulse.Lib.Core.inv",
"FStar.Pervasives.dsnd",
"Pulse.Lib.Core.inames"
] | [
"recursion"
] | false | false | false | true | false | let rec invlist_names (is: invlist0) : inames =
| match is with
| [] -> emp_inames
| i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i) | false |
Pulse.Lib.InvList.fsti | Pulse.Lib.InvList.invlist_empty | val invlist_empty:invlist | val invlist_empty:invlist | let invlist_empty : invlist = [] | {
"file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | module Pulse.Lib.InvList
open Pulse.Lib.Pervasives
let invlist_elem = p:vprop & inv p
let invlist0 = list invlist_elem
let rec invlist_names (is : invlist0) : inames =
match is with
| [] -> emp_inames
| i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i)
let rec invlist_nodups (is : invlist0) : prop =
match is with
| [] -> True
| i :: is -> not (mem_inv (invlist_names is) (dsnd i)) /\ invlist_nodups is
let invlist =
i:invlist0{invlist_nodups i} | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Priv.Trade0.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.InvList.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Lib.InvList.invlist | Prims.Tot | [
"total"
] | [] | [
"Prims.Nil",
"Pulse.Lib.InvList.invlist_elem"
] | [] | false | false | false | true | false | let invlist_empty:invlist =
| [] | false |
Pulse.Lib.InvList.fsti | Pulse.Lib.InvList.add_one | val add_one (h: invlist_elem) (t: invlist{not (mem_inv (invlist_names t) (dsnd h))}) : invlist | val add_one (h: invlist_elem) (t: invlist{not (mem_inv (invlist_names t) (dsnd h))}) : invlist | let add_one (h : invlist_elem) (t : invlist{not (mem_inv (invlist_names t) (dsnd h))}) : invlist =
h :: t | {
"file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 8,
"end_line": 24,
"start_col": 0,
"start_line": 23
} | module Pulse.Lib.InvList
open Pulse.Lib.Pervasives
let invlist_elem = p:vprop & inv p
let invlist0 = list invlist_elem
let rec invlist_names (is : invlist0) : inames =
match is with
| [] -> emp_inames
| i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i)
let rec invlist_nodups (is : invlist0) : prop =
match is with
| [] -> True
| i :: is -> not (mem_inv (invlist_names is) (dsnd i)) /\ invlist_nodups is
let invlist =
i:invlist0{invlist_nodups i}
let invlist_empty : invlist = [] | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Priv.Trade0.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.InvList.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
h: Pulse.Lib.InvList.invlist_elem ->
t:
Pulse.Lib.InvList.invlist
{ Prims.op_Negation (FStar.Ghost.reveal (Pulse.Lib.Core.mem_inv (Pulse.Lib.InvList.invlist_names
t)
(FStar.Pervasives.dsnd h))) }
-> Pulse.Lib.InvList.invlist | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.InvList.invlist_elem",
"Pulse.Lib.InvList.invlist",
"Prims.b2t",
"Prims.op_Negation",
"FStar.Ghost.reveal",
"Prims.bool",
"Pulse.Lib.Core.mem_inv",
"Prims.__proj__Mkdtuple2__item___1",
"Pulse.Lib.Core.vprop",
"Pulse.Lib.Core.inv",
"Pulse.Lib.InvList.invlist_names",
"FStar.Pervasives.dsnd",
"Prims.Cons"
] | [] | false | false | false | false | false | let add_one (h: invlist_elem) (t: invlist{not (mem_inv (invlist_names t) (dsnd h))}) : invlist =
| h :: t | false |
Pulse.Lib.InvList.fsti | Pulse.Lib.InvList.invlist_nodups | val invlist_nodups (is: invlist0) : prop | val invlist_nodups (is: invlist0) : prop | let rec invlist_nodups (is : invlist0) : prop =
match is with
| [] -> True
| i :: is -> not (mem_inv (invlist_names is) (dsnd i)) /\ invlist_nodups is | {
"file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 77,
"end_line": 16,
"start_col": 0,
"start_line": 13
} | module Pulse.Lib.InvList
open Pulse.Lib.Pervasives
let invlist_elem = p:vprop & inv p
let invlist0 = list invlist_elem
let rec invlist_names (is : invlist0) : inames =
match is with
| [] -> emp_inames
| i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Priv.Trade0.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.InvList.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | is: Pulse.Lib.InvList.invlist0 -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.InvList.invlist0",
"Prims.l_True",
"Pulse.Lib.InvList.invlist_elem",
"Prims.list",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Negation",
"FStar.Ghost.reveal",
"Prims.bool",
"Pulse.Lib.Core.mem_inv",
"Prims.__proj__Mkdtuple2__item___1",
"Pulse.Lib.Core.vprop",
"Pulse.Lib.Core.inv",
"Pulse.Lib.InvList.invlist_names",
"FStar.Pervasives.dsnd",
"Pulse.Lib.InvList.invlist_nodups",
"Prims.prop"
] | [
"recursion"
] | false | false | false | true | true | let rec invlist_nodups (is: invlist0) : prop =
| match is with
| [] -> True
| i :: is -> not (mem_inv (invlist_names is) (dsnd i)) /\ invlist_nodups is | false |
PulseCore.Preorder.fst | PulseCore.Preorder.split_current | val split_current (#a #p: _) (h: history a p {Current? h /\ (Current?.f h).v <=. one})
: half:
history a p
{ Current? h /\ composable pcm_history half half /\ op pcm_history half half == h /\
Current?.h half == Current?.h h /\ history_val half (hval h) (Current?.f half) } | val split_current (#a #p: _) (h: history a p {Current? h /\ (Current?.f h).v <=. one})
: half:
history a p
{ Current? h /\ composable pcm_history half half /\ op pcm_history half half == h /\
Current?.h half == Current?.h h /\ history_val half (hval h) (Current?.f half) } | let split_current #a #p (h:history a p { Current? h /\ (Current?.f h).v <=. one })
: half:history a p {
Current? h /\
composable pcm_history half half /\
op pcm_history half half == h /\
Current?.h half == Current?.h h /\
history_val half (hval h) (Current?.f half)
}
= let Current v p = h in
assert_spinoff (sum_perm (half_perm p) (half_perm p) == p);
Current v (half_perm p) | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 27,
"end_line": 438,
"start_col": 0,
"start_line": 428
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options
let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
}
let pcm_history_preorder #a #p : preorder (history a p) =
fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ ->
vh1 `extends` vh0
#push-options "--z3rlimit_factor 8 --ifuel 1 --fuel 0 --warn_error -271"
let pcm_history_induces_preorder #a #p
: Lemma (induces_preorder (pcm_history #a #p)
(pcm_history_preorder #a #p))
= let aux (x y:history a p)
(f:frame_preserving_upd (pcm_history #a #p) x y)
(v:history a p)
: Lemma
(requires compatible (pcm_history #a #p) x v)
(ensures (pcm_history_preorder #a #p) v (f v))
[SMTPat ()]
= let pcm = pcm_history #a #p in
let v1 = f v in
match x, v, v1 with
| Witnessed _, Witnessed _, Witnessed _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Witnessed _ -> ()
| Witnessed _, Current _ _, Witnessed _ -> ()
| Witnessed _, Witnessed _, Current _ _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Current _ _ -> ()
| Witnessed _, Current _ _, Current _ _ -> ()
| Current hx _, Current hv _, Witnessed _
| Current hx _, Current hv _, Current _ _ ->
let frame = FStar.IndefiniteDescription.indefinite_description_ghost
(history a p) (fun frame -> composable pcm x frame /\ op pcm frame x == v) in
match frame with
| Current hf _ -> ()
| Witnessed hf ->
assert (extends hx hf);
assert (hx == hv);
assert (composable pcm x (Witnessed hv))
in
()
#pop-options
let extend_history' #a #p (h0:history a p{Current? h0})
(v:a{p (hval h0) v})
: history a p
= let Current h f = h0 in
Current (v :: h) f
let extend_history'_is_frame_preserving #a #p
(h0:history a p{Current? h0 /\ hperm h0 == full_perm})
(v:a{p (hval h0) v})
: Lemma (frame_preserving pcm_history h0 (extend_history' h0 v))
= ()
let history_val #a #p (h:history a p) (v:Ghost.erased a) (f:perm)
: prop
= Current? h /\ hval h == v /\ hperm h == f /\ f.v <=. one | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | h: PulseCore.Preorder.history a p {Current? h /\ MkPerm?.v (Current?.f h) <=. FStar.Real.one}
-> half:
PulseCore.Preorder.history a p
{ Current? h /\ FStar.PCM.composable PulseCore.Preorder.pcm_history half half /\
FStar.PCM.op PulseCore.Preorder.pcm_history half half == h /\
Current?.h half == Current?.h h /\
PulseCore.Preorder.history_val half (PulseCore.Preorder.hval h) (Current?.f half) } | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"Prims.l_and",
"Prims.b2t",
"PulseCore.Preorder.uu___is_Current",
"FStar.Real.op_Less_Equals_Dot",
"PulseCore.FractionalPermission.__proj__MkPerm__item__v",
"PulseCore.Preorder.__proj__Current__item__f",
"FStar.Real.one",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"PulseCore.Preorder.Current",
"PulseCore.FractionalPermission.half_perm",
"Prims.unit",
"FStar.Pervasives.assert_spinoff",
"Prims.eq2",
"PulseCore.FractionalPermission.sum_perm",
"FStar.PCM.composable",
"PulseCore.Preorder.pcm_history",
"FStar.PCM.op",
"PulseCore.Preorder.__proj__Current__item__h",
"PulseCore.Preorder.history_val",
"PulseCore.Preorder.hval"
] | [] | false | false | false | false | false | let split_current #a #p (h: history a p {Current? h /\ (Current?.f h).v <=. one})
: half:
history a p
{ Current? h /\ composable pcm_history half half /\ op pcm_history half half == h /\
Current?.h half == Current?.h h /\ history_val half (hval h) (Current?.f half) } =
| let Current v p = h in
assert_spinoff (sum_perm (half_perm p) (half_perm p) == p);
Current v (half_perm p) | false |
LowParse.Low.Writers.Instances.fst | LowParse.Low.Writers.Instances.swrite_nondep_then' | val swrite_nondep_then'
(#h0: HS.mem)
(#sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong})
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong})
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot
(w:
swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0
{swvalue w == (swvalue w1, swvalue w2)}) | val swrite_nondep_then'
(#h0: HS.mem)
(#sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong})
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong})
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot
(w:
swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0
{swvalue w == (swvalue w1, swvalue w2)}) | let swrite_nondep_then'
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from ->
serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2);
serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2);
serialized_length_eq s1 (swvalue w1);
serialized_length_eq s2 (swvalue w2);
let pos1 = swrite w1 pout_from in
let pos2 = swrite w2 pos1 in
let h' = HST.get () in
valid_nondep_then h' p1 p2 sout pout_from;
pos2
) | {
"file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 70,
"start_col": 0,
"start_line": 42
} | module LowParse.Low.Writers.Instances
include LowParse.Low.Writers
include LowParse.Low.Combinators
include LowParse.Low.Bytes
include LowParse.Low.BitSum
module HS = FStar.HyperStack
module B = LowStar.Buffer
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
inline_for_extraction
noextract
let swrite_weaken
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(k2: parser_kind)
(w1: swriter s1 h0 space_beyond sout pout_from0 {
(k2 `is_weaker_than` k1) /\
k2.parser_kind_subkind == Some ParserStrong
})
: Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq s1 (swvalue w1);
serialized_length_eq (serialize_weaken k2 s1) (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_weaken k2 p1 h sout pout_from;
res
)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Endianness.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Low.Writers.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.Bytes.fst.checked",
"LowParse.Low.BitSum.fst.checked",
"LowParse.Endianness.BitFields.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Writers.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowParse.Low.BitSum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
w1: LowParse.Low.Writers.swriter s1 h0 space_beyond sout pout_from0 ->
w2: LowParse.Low.Writers.swriter s2 h0 space_beyond sout pout_from0
-> w:
LowParse.Low.Writers.swriter (LowParse.Spec.Combinators.serialize_nondep_then s1 s2)
h0
space_beyond
sout
pout_from0
{ LowParse.Low.Writers.swvalue w ==
(LowParse.Low.Writers.swvalue w1,
LowParse.Low.Writers.swvalue w2) } | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"LowParse.Slice.srel_of_buffer_srel",
"LowParse.Bytes.byte",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.t",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.nat",
"LowParse.Low.Writers.swriter",
"LowParse.Low.Writers.SWriter",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Spec.Combinators.serialize_nondep_then",
"FStar.Ghost.hide",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.Low.Writers.swvalue",
"Prims.unit",
"LowParse.Low.Combinators.valid_nondep_then",
"FStar.HyperStack.ST.get",
"LowParse.Low.Writers.swrite",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Spec.Combinators.serialize_nondep_then_eq"
] | [] | false | false | false | false | false | let swrite_nondep_then'
(#h0: HS.mem)
(#sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong})
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong})
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot
(w:
swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0
{swvalue w == (swvalue w1, swvalue w2)}) =
| SWriter (Ghost.hide (swvalue w1, swvalue w2))
(fun pout_from ->
serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2);
serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2);
serialized_length_eq s1 (swvalue w1);
serialized_length_eq s2 (swvalue w2);
let pos1 = swrite w1 pout_from in
let pos2 = swrite w2 pos1 in
let h' = HST.get () in
valid_nondep_then h' p1 p2 sout pout_from;
pos2) | false |
Pulse.Lib.InvList.fsti | Pulse.Lib.InvList.invlist_sub | val invlist_sub (is1 is2: invlist) : prop | val invlist_sub (is1 is2: invlist) : prop | let invlist_sub (is1 is2 : invlist) : prop =
inames_subset (invlist_names is1) (invlist_names is2) | {
"file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 55,
"end_line": 53,
"start_col": 0,
"start_line": 52
} | module Pulse.Lib.InvList
open Pulse.Lib.Pervasives
let invlist_elem = p:vprop & inv p
let invlist0 = list invlist_elem
let rec invlist_names (is : invlist0) : inames =
match is with
| [] -> emp_inames
| i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i)
let rec invlist_nodups (is : invlist0) : prop =
match is with
| [] -> True
| i :: is -> not (mem_inv (invlist_names is) (dsnd i)) /\ invlist_nodups is
let invlist =
i:invlist0{invlist_nodups i}
let invlist_empty : invlist = []
let add_one (h : invlist_elem) (t : invlist{not (mem_inv (invlist_names t) (dsnd h))}) : invlist =
h :: t
let rec invlist_v (is : invlist) : vprop =
match is with
| [] -> emp
| i :: is -> dfst i ** invlist_v is
val shift_invlist_one
(#a:Type0)
(p : vprop)
(i : inv p)
(is : invlist{not (mem_inv (invlist_names is) i)})
(#pre:vprop)
(#post : a -> vprop)
(f : unit -> stt_atomic a #Unobservable emp_inames (invlist_v ((| p, i |) :: is) ** pre) (fun v -> invlist_v ((| p, i |) :: is) ** post v)) :
unit -> stt_atomic a #Unobservable emp_inames (invlist_v is ** (p ** pre)) (fun v -> invlist_v is ** (p ** post v))
val with_invlist (#a:Type0) (#pre : vprop) (#post : a -> vprop)
(is : invlist)
(f : unit -> stt_atomic a #Unobservable emp_inames (invlist_v is ** pre) (fun v -> invlist_v is ** post v))
: stt_atomic a #Unobservable (invlist_names is) pre (fun v -> post v)
(* A helper for a ghost-unit function. *)
val with_invlist_ghost (#pre : vprop) (#post : vprop)
(is : invlist)
(f : unit -> stt_ghost unit (invlist_v is ** pre) (fun _ -> invlist_v is ** post))
: stt_atomic unit #Unobservable (invlist_names is) pre (fun _ -> post) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Priv.Trade0.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.InvList.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | is1: Pulse.Lib.InvList.invlist -> is2: Pulse.Lib.InvList.invlist -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.InvList.invlist",
"Pulse.Lib.Core.inames_subset",
"Pulse.Lib.InvList.invlist_names",
"Prims.prop"
] | [] | false | false | false | true | true | let invlist_sub (is1 is2: invlist) : prop =
| inames_subset (invlist_names is1) (invlist_names is2) | false |
Pulse.Lib.InvList.fsti | Pulse.Lib.InvList.invlist_v | val invlist_v (is: invlist) : vprop | val invlist_v (is: invlist) : vprop | let rec invlist_v (is : invlist) : vprop =
match is with
| [] -> emp
| i :: is -> dfst i ** invlist_v is | {
"file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 29,
"start_col": 0,
"start_line": 26
} | module Pulse.Lib.InvList
open Pulse.Lib.Pervasives
let invlist_elem = p:vprop & inv p
let invlist0 = list invlist_elem
let rec invlist_names (is : invlist0) : inames =
match is with
| [] -> emp_inames
| i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i)
let rec invlist_nodups (is : invlist0) : prop =
match is with
| [] -> True
| i :: is -> not (mem_inv (invlist_names is) (dsnd i)) /\ invlist_nodups is
let invlist =
i:invlist0{invlist_nodups i}
let invlist_empty : invlist = []
let add_one (h : invlist_elem) (t : invlist{not (mem_inv (invlist_names t) (dsnd h))}) : invlist =
h :: t | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Priv.Trade0.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.InvList.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | is: Pulse.Lib.InvList.invlist -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.InvList.invlist",
"Pulse.Lib.Core.emp",
"Pulse.Lib.InvList.invlist_elem",
"Prims.list",
"Pulse.Lib.Core.op_Star_Star",
"FStar.Pervasives.dfst",
"Pulse.Lib.Core.vprop",
"Pulse.Lib.Core.inv",
"Pulse.Lib.InvList.invlist_v"
] | [
"recursion"
] | false | false | false | true | false | let rec invlist_v (is: invlist) : vprop =
| match is with
| [] -> emp
| i :: is -> dfst i ** invlist_v is | false |
CPS.Double.fst | CPS.Double.eval_cps | val eval_cps : expr -> (int -> Tot 'a) -> Tot 'a | val eval_cps : expr -> (int -> Tot 'a) -> Tot 'a | let rec eval_cps e k =
match e with
| Const n -> k n
| Plus e1 e2 -> eval_cps e1 (fun r1 -> eval_cps e2 (fun r2 -> k (r1 + r2))) | {
"file_name": "examples/termination/CPS.Double.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 79,
"end_line": 24,
"start_col": 0,
"start_line": 21
} | (*
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.
*)
(** Standard implementation **)
module CPS.Double
open CPS.Expr | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"CPS.Expr.fst.checked"
],
"interface_file": false,
"source_file": "CPS.Double.fst"
} | [
{
"abbrev": false,
"full_module": "CPS.Expr",
"short_module": null
},
{
"abbrev": false,
"full_module": "CPS",
"short_module": null
},
{
"abbrev": false,
"full_module": "CPS",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: CPS.Expr.expr -> k: (_: Prims.int -> 'a) -> 'a | Prims.Tot | [
"total"
] | [] | [
"CPS.Expr.expr",
"Prims.int",
"CPS.Double.eval_cps",
"Prims.op_Addition"
] | [
"recursion"
] | false | false | false | true | false | let rec eval_cps e k =
| match e with
| Const n -> k n
| Plus e1 e2 -> eval_cps e1 (fun r1 -> eval_cps e2 (fun r2 -> k (r1 + r2))) | false |
LowParse.Low.Writers.Instances.fst | LowParse.Low.Writers.Instances.swrite_bounded_integer_ct | val swrite_bounded_integer_ct
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(i: U32.t{1 <= U32.v i /\ U32.v i <= 4})
(pout_from0: U32.t)
(x: bounded_integer (U32.v i))
: Tot
(y:
swriter (serialize_bounded_integer (U32.v i)) h0 (4 - U32.v i) sout pout_from0
{swvalue y == x}) | val swrite_bounded_integer_ct
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(i: U32.t{1 <= U32.v i /\ U32.v i <= 4})
(pout_from0: U32.t)
(x: bounded_integer (U32.v i))
: Tot
(y:
swriter (serialize_bounded_integer (U32.v i)) h0 (4 - U32.v i) sout pout_from0
{swvalue y == x}) | let swrite_bounded_integer_ct
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(i: U32.t { 1 <= U32.v i /\ U32.v i <= 4 })
(pout_from0: U32.t)
(x: bounded_integer (U32.v i))
: Tot (y: swriter (serialize_bounded_integer (U32.v i)) h0 (4 - U32.v i) sout pout_from0 { swvalue y == x } )
= SWriter (Ghost.hide x)
(fun pout_from ->
serialized_length_eq (serialize_bounded_integer (U32.v i)) x;
serialize32_bounded_integer_ct i x sout.base pout_from;
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h sout pout_from in
let small = bytes_of_slice_from_to h sout pout_from (pout_from `U32.add` i) in
parse_strong_prefix (parse_bounded_integer (U32.v i)) small large;
valid_facts (parse_bounded_integer (U32.v i)) h sout pout_from
in
pout_from `U32.add` i
) | {
"file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 368,
"start_col": 0,
"start_line": 349
} | module LowParse.Low.Writers.Instances
include LowParse.Low.Writers
include LowParse.Low.Combinators
include LowParse.Low.Bytes
include LowParse.Low.BitSum
module HS = FStar.HyperStack
module B = LowStar.Buffer
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
inline_for_extraction
noextract
let swrite_weaken
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(k2: parser_kind)
(w1: swriter s1 h0 space_beyond sout pout_from0 {
(k2 `is_weaker_than` k1) /\
k2.parser_kind_subkind == Some ParserStrong
})
: Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq s1 (swvalue w1);
serialized_length_eq (serialize_weaken k2 s1) (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_weaken k2 p1 h sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_nondep_then'
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from ->
serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2);
serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2);
serialized_length_eq s1 (swvalue w1);
serialized_length_eq s2 (swvalue w2);
let pos1 = swrite w1 pout_from in
let pos2 = swrite w2 pos1 in
let h' = HST.get () in
valid_nondep_then h' p1 p2 sout pout_from;
pos2
)
let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2
inline_for_extraction
noextract
let swrite_nondep_then
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond1: nat)
(w1: swriter s1 h0 space_beyond1 sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(#space_beyond2: nat)
(w2: swriter s2 h0 space_beyond2 sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= [@inline_let]
let sbmax = space_beyond1 `max` space_beyond2 in
weaken_swriter w1 h0 sbmax pout_from0 `swrite_nondep_then'` weaken_swriter w2 h0 sbmax pout_from0
inline_for_extraction
noextract
let swrite_filter
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(cond: (t1 -> GTot bool))
(w1: swriter s1 h0 space_beyond sout pout_from0 { cond (swvalue w1) } )
: Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq (serialize_filter s1 cond) (swvalue w1);
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_filter h p1 cond sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_synth
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#t2: Type)
(f12: (t1 -> GTot t2))
(f21: (t2 -> GTot t1))
(prf: squash (
synth_injective f12 /\
synth_inverse f12 f21
))
: Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 {
swvalue w2 == f12 (swvalue w1) /\
swvalue w1 == f21 (swvalue w2)
})
= [@inline_let] let _ =
serialize_synth_eq p1 f12 s1 f21 () (f12 (swvalue w1));
synth_injective_synth_inverse_synth_inverse_recip f12 f21 ()
in
SWriter (Ghost.hide (f12 (swvalue w1))) (fun pout_from ->
serialized_length_eq (serialize_synth p1 f12 s1 f21 ()) (f12 (swvalue w1));
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_synth h p1 f12 sout pout_from;
res
)
module U8 = FStar.UInt8
module FB = FStar.Bytes
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let swrite_flbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(len: U32.t)
(b: B.buffer U8.t {
B.live h0 b /\
B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_flbytes (U32.v len)) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_flbytes (U32.v len)) (FB.hide (B.as_seq h0 b));
let payload = B.sub sout.base pout_from len in
B.blit b 0ul payload 0ul len;
let h = HST.get () in
valid_flbytes_intro h (U32.v len) sout pout_from;
pout_from `U32.add` len
)
inline_for_extraction
noextract
let swrite_bounded_vlbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(len: U32.t { min <= U32.v len /\ U32.v len <= max })
(b: B.buffer U8.t {
B.length b == U32.v len /\
B.live h0 b /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_bounded_vlbytes min max) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_bounded_vlbytes min max) (FB.hide (B.as_seq h0 b));
length_serialize_bounded_vlbytes min max (FB.hide (B.as_seq h0 b));
let pout_payload = pout_from `U32.add` U32.uint_to_t (log256' max) in
let payload = B.sub sout.base pout_payload len in
B.blit b 0ul payload 0ul len;
finalize_bounded_vlbytes min max sout pout_from len
)
inline_for_extraction
noextract
let swrite_bounded_vlgenbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk { kk.parser_kind_subkind == Some ParserStrong })
(wk: leaf_writer_strong sk)
(len: U32.t { min <= U32.v len /\ U32.v len <= max })
(b: B.buffer U8.t {
B.live h0 b /\
B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_bounded_vlgenbytes min max sk) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_bounded_vlgenbytes min max sk) (FB.hide (B.as_seq h0 b));
length_serialize_bounded_vlgenbytes min max sk (FB.hide (B.as_seq h0 b));
serialized_length_eq sk len;
let pout_payload = swrite (swrite_leaf wk h0 sout pout_from0 len) pout_from in
let payload = B.sub sout.base pout_payload len in
B.blit b 0ul payload 0ul len;
let h = HST.get () in
valid_bounded_vlgenbytes min max pk sout pout_from h;
pout_payload `U32.add` len
)
#pop-options
#push-options "--z3rlimit 32"
inline_for_extraction
noextract
let swrite_bitsum
(h0: HS.mem)
(space_beyond: nat)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(#s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(w_tg: leaf_writer_strong s)
(mk: synth_bitsum'_recip_t b)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(k: bitsum'_type b {
(parse_bitsum_kind kt b type_of_tag f).parser_kind_subkind == Some ParserStrong /\
(dfst (f (bitsum'_key_of_t b k))).parser_kind_subkind == Some ParserStrong
})
(w_pl: swriter (g (bitsum'_key_of_t b k)) h0 space_beyond sout pout_from0)
: Tot (w' : swriter (serialize_bitsum b tag_of_data type_of_tag synth_case s #f g) h0 space_beyond sout pout_from0 {
swvalue w' == synth_case.f k (swvalue w_pl)
})
= SWriter (Ghost.hide (synth_case.f k (swvalue w_pl))) (fun pout_from ->
serialized_length_eq (serialize_bitsum b tag_of_data type_of_tag synth_case s #f g) (synth_case.f k (swvalue w_pl));
serialized_length_eq s (synth_bitsum'_recip b k);
serialized_length_eq (g (bitsum'_key_of_t b k)) (swvalue w_pl);
serialize_bitsum_eq_2 b tag_of_data type_of_tag synth_case s g k (swvalue w_pl);
let pos1 = w_tg (mk k) sout pout_from in
let pos2 = swrite w_pl pos1 in
let h = HST.get () in
valid_filter h p (filter_bitsum' b) sout pout_from;
synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
assert (filter_bitsum' b (mk k) == true);
assert (synth_bitsum' b (mk k) == k);
valid_synth h (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) sout pout_from;
valid_bitsum_intro b tag_of_data type_of_tag synth_case p f h sout pout_from;
pos2
)
#pop-options
module BF = LowParse.BitFields
module E = LowParse.Endianness.BitFields
module LE = LowStar.Endianness
#push-options "--z3rlimit 16"
inline_for_extraction
let serialize32_bounded_integer_ct
(i: U32.t { 1 <= U32.v i /\ U32.v i <= 4 })
(x: bounded_integer (U32.v i))
(b: B.buffer byte)
(pos: U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h b /\
U32.v pos + 4 <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` i)) h h' /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v i) == serialize (serialize_bounded_integer (U32.v i)) x
))
= let h = HST.get () in
let before = LE.load32_be_i b pos in
bounded_integer_prop_equiv (U32.v i) x;
let after = BF.uint32.BF.set_bitfield_gen before (8ul `U32.mul` (4ul `U32.sub` i)) 32ul x in
LE.store32_be_i b pos after;
let h' = HST.get () in
parse_bounded_integer_spec (U32.v i) (Seq.slice (B.as_seq h b) (U32.v pos) (B.length b));
E.n_to_be_be_to_n 4 (Seq.slice (Seq.slice (B.as_seq h b) (U32.v pos) (B.length b)) 0 4);
Seq.slice_slice (B.as_seq h b) (U32.v pos) (B.length b) 0 4;
Seq.slice_slice (B.as_seq h' b) (U32.v pos) (B.length b) 0 4;
E.slice_n_to_be_bitfield 4 (U32.v before) (U32.v i) 4;
E.slice_n_to_be_bitfield 4 (U32.v after) (U32.v i) 4;
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 4)) (U32.v i);
Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)) (U32.v i);
BF.get_bitfield_set_bitfield_other #32 (U32.v before) (8 `op_Multiply` (4 - U32.v i)) 32 (U32.v x) 0 (8 `op_Multiply` (4 - U32.v i));
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos + U32.v i) (B.length b)) (4 - U32.v i);
Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos + U32.v i) (B.length b)) (4 - U32.v i);
B.modifies_loc_buffer_from_to_intro b pos (pos `U32.add` i) B.loc_none h h';
E.slice_n_to_be_bitfield 4 (U32.v after) 0 (U32.v i);
BF.get_bitfield_set_bitfield_same #32 (U32.v before) (8 `op_Multiply` (4 - U32.v i)) 32 (U32.v x);
serialize_bounded_integer_spec (U32.v i) x
#pop-options
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Endianness.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Low.Writers.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.Bytes.fst.checked",
"LowParse.Low.BitSum.fst.checked",
"LowParse.Endianness.BitFields.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Writers.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Endianness",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "LowParse.Endianness.BitFields",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "FB"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowParse.Low.BitSum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
h0: FStar.Monotonic.HyperStack.mem ->
sout:
LowParse.Slice.slice (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte
))
(LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte)) ->
i: FStar.UInt32.t{1 <= FStar.UInt32.v i /\ FStar.UInt32.v i <= 4} ->
pout_from0: FStar.UInt32.t ->
x: LowParse.Spec.BoundedInt.bounded_integer (FStar.UInt32.v i)
-> y:
LowParse.Low.Writers.swriter (LowParse.Spec.BoundedInt.serialize_bounded_integer (FStar.UInt32.v
i))
h0
(4 - FStar.UInt32.v i)
sout
pout_from0 {LowParse.Low.Writers.swvalue y == x} | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"LowParse.Slice.srel_of_buffer_srel",
"LowParse.Bytes.byte",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Low.Writers.SWriter",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.BoundedInt.serialize_bounded_integer",
"Prims.op_Subtraction",
"FStar.Ghost.hide",
"FStar.UInt32.add",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Bytes.bytes",
"LowParse.Low.Base.Spec.bytes_of_slice_from_to",
"LowParse.Slice.bytes_of_slice_from",
"FStar.HyperStack.ST.get",
"LowParse.Low.Writers.Instances.serialize32_bounded_integer_ct",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Writers.swriter",
"Prims.eq2",
"LowParse.Low.Writers.swvalue"
] | [] | false | false | false | false | false | let swrite_bounded_integer_ct
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(i: U32.t{1 <= U32.v i /\ U32.v i <= 4})
(pout_from0: U32.t)
(x: bounded_integer (U32.v i))
: Tot
(y:
swriter (serialize_bounded_integer (U32.v i)) h0 (4 - U32.v i) sout pout_from0
{swvalue y == x}) =
| SWriter (Ghost.hide x)
(fun pout_from ->
serialized_length_eq (serialize_bounded_integer (U32.v i)) x;
serialize32_bounded_integer_ct i x sout.base pout_from;
let h = HST.get () in
[@@ inline_let ]let _ =
let large = bytes_of_slice_from h sout pout_from in
let small = bytes_of_slice_from_to h sout pout_from (pout_from `U32.add` i) in
parse_strong_prefix (parse_bounded_integer (U32.v i)) small large;
valid_facts (parse_bounded_integer (U32.v i)) h sout pout_from
in
pout_from `U32.add` i) | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield16_msb_first | val get_bitfield16_msb_first
(value: U16.t)
(bitsFrom: U32.t{U32.v bitsFrom < 16})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i: U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)} | val get_bitfield16_msb_first
(value: U16.t)
(bitsFrom: U32.t{U32.v bitsFrom < 16})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i: U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)} | let get_bitfield16_msb_first (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= get_bitfield16 value (16ul `U32.sub` bitsTo) (16ul `U32.sub` bitsFrom) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 75,
"end_line": 57,
"start_col": 0,
"start_line": 53
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default
// following MSVC (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields)
let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2
let get_bitfield16 (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield32 (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint32.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield64 (value:U64.t)
(bitsFrom:U32.t{U32.v bitsFrom < 64})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i:U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint64.LBF.get_bitfield_gen value bitsFrom bitsTo
// Most significant bit first variants:
let get_bitfield8_msb_first
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= get_bitfield8 value (8ul `U32.sub` bitsTo) (8ul `U32.sub` bitsFrom) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt16.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 16} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 16}
-> i:
FStar.UInt16.t
{FStar.UInt.size (FStar.UInt16.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt16.t",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"EverParse3d.Prelude.StaticHeader.get_bitfield16",
"FStar.UInt32.sub",
"FStar.UInt32.__uint_to_t",
"FStar.UInt.size",
"FStar.UInt16.v",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield16_msb_first
(value: U16.t)
(bitsFrom: U32.t{U32.v bitsFrom < 16})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i: U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)} =
| get_bitfield16 value (16ul `U32.sub` bitsTo) (16ul `U32.sub` bitsFrom) | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield8 | val get_bitfield8
(value: U8.t)
(bitsFrom: U32.t{U32.v bitsFrom < 8})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i: U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)}) | val get_bitfield8
(value: U8.t)
(bitsFrom: U32.t{U32.v bitsFrom < 8})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i: U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)}) | let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2 | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 24,
"start_col": 0,
"start_line": 15
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt8.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 8} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 8}
-> i:
FStar.UInt8.t
{FStar.UInt.size (FStar.UInt8.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.UInt8.shift_right",
"FStar.UInt32.add",
"FStar.UInt32.sub",
"FStar.UInt32.__uint_to_t",
"FStar.UInt8.shift_left",
"Prims.unit",
"LowParse.BitFields.get_bitfield_eq_2",
"FStar.UInt8.v",
"FStar.UInt.size",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield8
(value: U8.t)
(bitsFrom: U32.t{U32.v bitsFrom < 8})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i: U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)}) =
| LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2 | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield16 | val get_bitfield16
(value: U16.t)
(bitsFrom: U32.t{U32.v bitsFrom < 16})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i: U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)} | val get_bitfield16
(value: U16.t)
(bitsFrom: U32.t{U32.v bitsFrom < 16})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i: U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)} | let get_bitfield16 (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 58,
"end_line": 30,
"start_col": 0,
"start_line": 26
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default
// following MSVC (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields)
let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt16.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 16} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 16}
-> i:
FStar.UInt16.t
{FStar.UInt.size (FStar.UInt16.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt16.t",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield_gen",
"LowParse.BitFields.uint16",
"FStar.UInt.size",
"FStar.UInt16.v",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield16
(value: U16.t)
(bitsFrom: U32.t{U32.v bitsFrom < 16})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i: U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)} =
| LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield64 | val get_bitfield64
(value: U64.t)
(bitsFrom: U32.t{U32.v bitsFrom < 64})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i: U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)} | val get_bitfield64
(value: U64.t)
(bitsFrom: U32.t{U32.v bitsFrom < 64})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i: U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)} | let get_bitfield64 (value:U64.t)
(bitsFrom:U32.t{U32.v bitsFrom < 64})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i:U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint64.LBF.get_bitfield_gen value bitsFrom bitsTo | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 58,
"end_line": 42,
"start_col": 0,
"start_line": 38
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default
// following MSVC (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields)
let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2
let get_bitfield16 (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield32 (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint32.LBF.get_bitfield_gen value bitsFrom bitsTo | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt64.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 64} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 64}
-> i:
FStar.UInt64.t
{FStar.UInt.size (FStar.UInt64.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield_gen",
"LowParse.BitFields.uint64",
"FStar.UInt.size",
"FStar.UInt64.v",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield64
(value: U64.t)
(bitsFrom: U32.t{U32.v bitsFrom < 64})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i: U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)} =
| LBF.uint64.LBF.get_bitfield_gen value bitsFrom bitsTo | false |
Hacl.HPKE.Interface.AEAD.fst | Hacl.HPKE.Interface.AEAD.aead_encrypt_cp128 | val aead_encrypt_cp128 : aead_encrypt_st (S.Seal AEAD.CHACHA20_POLY1305) | val aead_encrypt_cp128 : aead_encrypt_st (S.Seal AEAD.CHACHA20_POLY1305) | let aead_encrypt_cp128 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_128.encrypt cipher tag input len aad alen key nonce | {
"file_name": "code/hpke/Hacl.HPKE.Interface.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 39,
"start_col": 0,
"start_line": 35
} | module Hacl.HPKE.Interface.AEAD
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.Buffer
friend Spec.Agile.AEAD
/// These two functions will never be extracted, they are only an interface
/// boundary for the tactic performing instantiations.
/// In other files, it is exposed as an assume val, but for AEAD, we need an fsti
/// since we need to friend Spec.Agile.AEAD to perform the instantiations below,
/// and assume val are forbidden in interface files
let aead_encrypt #cs = admit()
let aead_decrypt #cs = admit()
#set-options "--z3rlimit 60 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let aead_encrypt_cp32 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_32.encrypt cipher tag input len aad alen key nonce
inline_for_extraction noextract
let aead_decrypt_cp32 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_32.decrypt input cipher len aad alen key nonce tag | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Chacha20Poly1305_32.fst.checked",
"Hacl.Chacha20Poly1305_256.fst.checked",
"Hacl.Chacha20Poly1305_128.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.Interface.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.HPKE.Interface.AEAD.aead_encrypt_st (Spec.Agile.HPKE.Seal Spec.Agile.AEAD.CHACHA20_POLY1305) | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.l_and",
"Prims.b2t",
"Spec.Agile.HPKE.uu___is_Seal",
"Spec.Agile.HPKE.Seal",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"Spec.Agile.HPKE.is_valid_aead",
"Hacl.HPKE.Interface.AEAD.kv",
"Spec.Agile.HPKE.__proj__Seal__item__alg",
"Hacl.HPKE.Interface.AEAD.iv",
"Lib.IntTypes.size_t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Agile.AEAD.max_length",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.size",
"Hacl.Chacha20Poly1305_128.encrypt",
"Prims.unit",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let aead_encrypt_cp128 =
| fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_128.encrypt cipher tag input len aad alen key nonce | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield32 | val get_bitfield32
(value: U32.t)
(bitsFrom: U32.t{U32.v bitsFrom < 32})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i: U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)} | val get_bitfield32
(value: U32.t)
(bitsFrom: U32.t{U32.v bitsFrom < 32})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i: U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)} | let get_bitfield32 (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint32.LBF.get_bitfield_gen value bitsFrom bitsTo | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 58,
"end_line": 36,
"start_col": 0,
"start_line": 32
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default
// following MSVC (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields)
let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2
let get_bitfield16 (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt32.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 32} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 32}
-> i:
FStar.UInt32.t
{FStar.UInt.size (FStar.UInt32.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield_gen",
"LowParse.BitFields.uint32",
"FStar.UInt.size",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield32
(value: U32.t)
(bitsFrom: U32.t{U32.v bitsFrom < 32})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i: U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)} =
| LBF.uint32.LBF.get_bitfield_gen value bitsFrom bitsTo | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield8_msb_first | val get_bitfield8_msb_first
(value: U8.t)
(bitsFrom: U32.t{U32.v bitsFrom < 8})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i: U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)}) | val get_bitfield8_msb_first
(value: U8.t)
(bitsFrom: U32.t{U32.v bitsFrom < 8})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i: U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)}) | let get_bitfield8_msb_first
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= get_bitfield8 value (8ul `U32.sub` bitsTo) (8ul `U32.sub` bitsFrom) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 69,
"end_line": 51,
"start_col": 0,
"start_line": 46
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default
// following MSVC (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields)
let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2
let get_bitfield16 (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield32 (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint32.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield64 (value:U64.t)
(bitsFrom:U32.t{U32.v bitsFrom < 64})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i:U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint64.LBF.get_bitfield_gen value bitsFrom bitsTo
// Most significant bit first variants: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt8.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 8} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 8}
-> i:
FStar.UInt8.t
{FStar.UInt.size (FStar.UInt8.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"EverParse3d.Prelude.StaticHeader.get_bitfield8",
"FStar.UInt32.sub",
"FStar.UInt32.__uint_to_t",
"FStar.UInt.size",
"FStar.UInt8.v",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield8_msb_first
(value: U8.t)
(bitsFrom: U32.t{U32.v bitsFrom < 8})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i: U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)}) =
| get_bitfield8 value (8ul `U32.sub` bitsTo) (8ul `U32.sub` bitsFrom) | false |
Hacl.Ed25519.fst | Hacl.Ed25519.secret_expand | val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit
(requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret)
(ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\
(let a, prefix = S.secret_expand (as_seq h0 secret) in
as_seq h1 (gsub expanded 0ul 32ul) == a /\
as_seq h1 (gsub expanded 32ul 32ul) == prefix)) | val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit
(requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret)
(ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\
(let a, prefix = S.secret_expand (as_seq h0 secret) in
as_seq h1 (gsub expanded 0ul 32ul) == a /\
as_seq h1 (gsub expanded 32ul 32ul) == prefix)) | let secret_expand expanded secret =
assert_norm (pow2 32 <= pow2 125 - 1);
Hacl.Streaming.SHA2.hash_512 expanded secret 32ul;
let h_low = sub expanded 0ul 32ul in
let h_low0 = h_low.( 0ul) in
let h_low31 = h_low.(31ul) in
h_low.( 0ul) <- h_low0 &. u8 0xf8;
h_low.(31ul) <- (h_low31 &. u8 127) |. u8 64 | {
"file_name": "code/ed25519/Hacl.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 29,
"start_col": 0,
"start_line": 22
} | module Hacl.Ed25519
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module S = Spec.Ed25519
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit
(requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret)
(ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\
(let a, prefix = S.secret_expand (as_seq h0 secret) in
as_seq h1 (gsub expanded 0ul 32ul) == a /\
as_seq h1 (gsub expanded 32ul 32ul) == prefix)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Impl.Ed25519.Verify.fst.checked",
"Hacl.Impl.Ed25519.Sign.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": 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.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
expanded: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
secret: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.u8",
"Prims.unit",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Hacl.Streaming.SHA2.hash_512",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.pow2",
"Prims.op_Subtraction"
] | [] | false | true | false | false | false | let secret_expand expanded secret =
| assert_norm (pow2 32 <= pow2 125 - 1);
Hacl.Streaming.SHA2.hash_512 expanded secret 32ul;
let h_low = sub expanded 0ul 32ul in
let h_low0 = h_low.(0ul) in
let h_low31 = h_low.(31ul) in
h_low.(0ul) <- h_low0 &. u8 0xf8;
h_low.(31ul) <- (h_low31 &. u8 127) |. u8 64 | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield32_msb_first | val get_bitfield32_msb_first
(value: U32.t)
(bitsFrom: U32.t{U32.v bitsFrom < 32})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i: U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)} | val get_bitfield32_msb_first
(value: U32.t)
(bitsFrom: U32.t{U32.v bitsFrom < 32})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i: U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)} | let get_bitfield32_msb_first (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= get_bitfield32 value (32ul `U32.sub` bitsTo) (32ul `U32.sub` bitsFrom) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 75,
"end_line": 63,
"start_col": 0,
"start_line": 59
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default
// following MSVC (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields)
let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2
let get_bitfield16 (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield32 (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint32.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield64 (value:U64.t)
(bitsFrom:U32.t{U32.v bitsFrom < 64})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i:U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint64.LBF.get_bitfield_gen value bitsFrom bitsTo
// Most significant bit first variants:
let get_bitfield8_msb_first
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= get_bitfield8 value (8ul `U32.sub` bitsTo) (8ul `U32.sub` bitsFrom)
let get_bitfield16_msb_first (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= get_bitfield16 value (16ul `U32.sub` bitsTo) (16ul `U32.sub` bitsFrom) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt32.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 32} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 32}
-> i:
FStar.UInt32.t
{FStar.UInt.size (FStar.UInt32.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"EverParse3d.Prelude.StaticHeader.get_bitfield32",
"FStar.UInt32.sub",
"FStar.UInt32.__uint_to_t",
"FStar.UInt.size",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield32_msb_first
(value: U32.t)
(bitsFrom: U32.t{U32.v bitsFrom < 32})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i: U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)} =
| get_bitfield32 value (32ul `U32.sub` bitsTo) (32ul `U32.sub` bitsFrom) | false |
EverParse3d.Prelude.StaticHeader.fst | EverParse3d.Prelude.StaticHeader.get_bitfield64_msb_first | val get_bitfield64_msb_first
(value: U64.t)
(bitsFrom: U32.t{U32.v bitsFrom < 64})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i: U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)} | val get_bitfield64_msb_first
(value: U64.t)
(bitsFrom: U32.t{U32.v bitsFrom < 64})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i: U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)} | let get_bitfield64_msb_first (value:U64.t)
(bitsFrom:U32.t{U32.v bitsFrom < 64})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i:U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)}
= get_bitfield64 value (64ul `U32.sub` bitsTo) (64ul `U32.sub` bitsFrom) | {
"file_name": "src/3d/prelude/EverParse3d.Prelude.StaticHeader.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 75,
"end_line": 69,
"start_col": 0,
"start_line": 65
} | module EverParse3d.Prelude.StaticHeader
module U64 = FStar.UInt64
module U32 = FStar.UInt32
module U16 = FStar.UInt16
module U8 = FStar.UInt8
module LBF = LowParse.BitFields
////////////////////////////////////////////////////////////////////////////////
// Bit fields
////////////////////////////////////////////////////////////////////////////////
// The get_bitfield operators are least significant bit first by default
// following MSVC (https://learn.microsoft.com/en-us/cpp/c-language/c-bit-fields)
let get_bitfield8
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= LBF.get_bitfield_eq_2 #8 (U8.v value) (U32.v bitsFrom) (U32.v bitsTo);
(* NOTE: due to https://github.com/FStarLang/karamel/issues/102 I need to introduce explicit let-bindings here *)
let op1 = value `U8.shift_left` (8ul `U32.sub` bitsTo) in
let op2 = op1 `U8.shift_right` ((8ul `U32.sub` bitsTo) `U32.add` bitsFrom) in
op2
let get_bitfield16 (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint16.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield32 (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint32.LBF.get_bitfield_gen value bitsFrom bitsTo
let get_bitfield64 (value:U64.t)
(bitsFrom:U32.t{U32.v bitsFrom < 64})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i:U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)}
= LBF.uint64.LBF.get_bitfield_gen value bitsFrom bitsTo
// Most significant bit first variants:
let get_bitfield8_msb_first
(value:U8.t)
(bitsFrom:U32.t{U32.v bitsFrom < 8})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 8})
: Tot (i:U8.t{FStar.UInt.size (U8.v i) (U32.v bitsTo - U32.v bitsFrom)})
= get_bitfield8 value (8ul `U32.sub` bitsTo) (8ul `U32.sub` bitsFrom)
let get_bitfield16_msb_first (value:U16.t)
(bitsFrom:U32.t{U32.v bitsFrom < 16})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 16})
: i:U16.t{FStar.UInt.size (U16.v i) (U32.v bitsTo - U32.v bitsFrom)}
= get_bitfield16 value (16ul `U32.sub` bitsTo) (16ul `U32.sub` bitsFrom)
let get_bitfield32_msb_first (value:U32.t)
(bitsFrom:U32.t{U32.v bitsFrom < 32})
(bitsTo:U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 32})
: i:U32.t{FStar.UInt.size (U32.v i) (U32.v bitsTo - U32.v bitsFrom)}
= get_bitfield32 value (32ul `U32.sub` bitsTo) (32ul `U32.sub` bitsFrom) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverParse3d.Prelude.StaticHeader.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "LBF"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
value: FStar.UInt64.t ->
bitsFrom: FStar.UInt32.t{FStar.UInt32.v bitsFrom < 64} ->
bitsTo:
FStar.UInt32.t{FStar.UInt32.v bitsFrom < FStar.UInt32.v bitsTo /\ FStar.UInt32.v bitsTo <= 64}
-> i:
FStar.UInt64.t
{FStar.UInt.size (FStar.UInt64.v i) (FStar.UInt32.v bitsTo - FStar.UInt32.v bitsFrom)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"EverParse3d.Prelude.StaticHeader.get_bitfield64",
"FStar.UInt32.sub",
"FStar.UInt32.__uint_to_t",
"FStar.UInt.size",
"FStar.UInt64.v",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_bitfield64_msb_first
(value: U64.t)
(bitsFrom: U32.t{U32.v bitsFrom < 64})
(bitsTo: U32.t{U32.v bitsFrom < U32.v bitsTo /\ U32.v bitsTo <= 64})
: i: U64.t{FStar.UInt.size (U64.v i) (U32.v bitsTo - U32.v bitsFrom)} =
| get_bitfield64 value (64ul `U32.sub` bitsTo) (64ul `U32.sub` bitsFrom) | false |
PulseTutorial.ImplicationAndForall.fst | PulseTutorial.ImplicationAndForall.regain_half_q | val regain_half_q : x: Pulse.Lib.GhostReference.ref a -> Pulse.Lib.Core.vprop | let regain_half_q #a (x:GR.ref a) =
forall* u. pts_to x #one_half u @==> pts_to x u | {
"file_name": "share/steel/examples/pulse/by-example/PulseTutorial.ImplicationAndForall.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 49,
"end_line": 47,
"start_col": 0,
"start_line": 46
} | module PulseTutorial.ImplicationAndForall
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick.Util
open Pulse.Lib.Forall.Util
module I = Pulse.Lib.Stick.Util
module GR = Pulse.Lib.GhostReference
open GR
//regain_half$
let regain_half #a (x:GR.ref a) (v:a) =
pts_to x #one_half v @==> pts_to x v
//regain_half$
```pulse //intro_regain_half$
ghost
fn intro_regain_half (x:GR.ref int)
requires pts_to x 'v
ensures pts_to x #one_half 'v ** regain_half x 'v
{
ghost
fn aux ()
requires pts_to x #one_half 'v ** pts_to x #one_half 'v
ensures pts_to x 'v
{
GR.gather x;
};
GR.share x;
I.intro _ _ _ aux;
fold regain_half;
}
```
```pulse //use_regain_half$
ghost
fn use_regain_half (x:GR.ref int)
requires pts_to x #one_half 'v ** regain_half x 'v
ensures pts_to x 'v
{
unfold regain_half;
I.elim _ _;
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.Util.fst.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.GhostReference.fsti.checked",
"Pulse.Lib.Forall.Util.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "PulseTutorial.ImplicationAndForall.fst"
} | [
{
"abbrev": false,
"full_module": "GR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.GhostReference",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Lib.GhostReference",
"short_module": "GR"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseTutorial",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseTutorial",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Lib.GhostReference.ref a -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.GhostReference.ref",
"Pulse.Lib.Forall.op_forall_Star",
"Pulse.Lib.Stick.op_At_Equals_Equals_Greater",
"Pulse.Lib.GhostReference.pts_to",
"Pulse.Lib.Core.one_half",
"PulseCore.FractionalPermission.full_perm",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | true | false | let regain_half_q #a (x: GR.ref a) =
| forall* u. pts_to x #one_half u @==> pts_to x u | false |
|
PulseTutorial.ImplicationAndForall.fst | PulseTutorial.ImplicationAndForall.regain_half | val regain_half : x: Pulse.Lib.GhostReference.ref a -> v: a -> Pulse.Lib.Core.vprop | let regain_half #a (x:GR.ref a) (v:a) =
pts_to x #one_half v @==> pts_to x v | {
"file_name": "share/steel/examples/pulse/by-example/PulseTutorial.ImplicationAndForall.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 11,
"start_col": 0,
"start_line": 10
} | module PulseTutorial.ImplicationAndForall
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick.Util
open Pulse.Lib.Forall.Util
module I = Pulse.Lib.Stick.Util
module GR = Pulse.Lib.GhostReference
open GR | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.Util.fst.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.GhostReference.fsti.checked",
"Pulse.Lib.Forall.Util.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "PulseTutorial.ImplicationAndForall.fst"
} | [
{
"abbrev": false,
"full_module": "GR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.GhostReference",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Lib.GhostReference",
"short_module": "GR"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseTutorial",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseTutorial",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Lib.GhostReference.ref a -> v: a -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.GhostReference.ref",
"Pulse.Lib.Stick.op_At_Equals_Equals_Greater",
"Pulse.Lib.GhostReference.pts_to",
"Pulse.Lib.Core.one_half",
"PulseCore.FractionalPermission.full_perm",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | true | false | let regain_half #a (x: GR.ref a) (v: a) =
| pts_to x #one_half v @==> pts_to x v | false |
|
Hacl.Ed25519.fst | Hacl.Ed25519.secret_to_public | val secret_to_public:
public_key:lbuffer uint8 32ul
-> private_key:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h public_key /\ live h private_key /\ disjoint public_key private_key)
(ensures fun h0 _ h1 -> modifies (loc public_key) h0 h1 /\
as_seq h1 public_key == Spec.Ed25519.secret_to_public (as_seq h0 private_key)) | val secret_to_public:
public_key:lbuffer uint8 32ul
-> private_key:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h public_key /\ live h private_key /\ disjoint public_key private_key)
(ensures fun h0 _ h1 -> modifies (loc public_key) h0 h1 /\
as_seq h1 public_key == Spec.Ed25519.secret_to_public (as_seq h0 private_key)) | let secret_to_public public_key private_key =
push_frame ();
let expanded_secret = create 64ul (u8 0) in
secret_expand expanded_secret private_key;
let a = sub expanded_secret 0ul 32ul in
Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key a;
pop_frame () | {
"file_name": "code/ed25519/Hacl.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 38,
"start_col": 0,
"start_line": 32
} | module Hacl.Ed25519
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module S = Spec.Ed25519
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit
(requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret)
(ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\
(let a, prefix = S.secret_expand (as_seq h0 secret) in
as_seq h1 (gsub expanded 0ul 32ul) == a /\
as_seq h1 (gsub expanded 32ul 32ul) == prefix))
[@CInline]
let secret_expand expanded secret =
assert_norm (pow2 32 <= pow2 125 - 1);
Hacl.Streaming.SHA2.hash_512 expanded secret 32ul;
let h_low = sub expanded 0ul 32ul in
let h_low0 = h_low.( 0ul) in
let h_low31 = h_low.(31ul) in
h_low.( 0ul) <- h_low0 &. u8 0xf8;
h_low.(31ul) <- (h_low31 &. u8 127) |. u8 64 | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Impl.Ed25519.Verify.fst.checked",
"Hacl.Impl.Ed25519.Sign.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
private_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Ed25519.Sign.point_mul_g_compress",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Hacl.Ed25519.secret_expand",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let secret_to_public public_key private_key =
| push_frame ();
let expanded_secret = create 64ul (u8 0) in
secret_expand expanded_secret private_key;
let a = sub expanded_secret 0ul 32ul in
Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key a;
pop_frame () | false |
Hacl.Ed25519.fst | Hacl.Ed25519.expand_keys | val expand_keys:
expanded_keys:lbuffer uint8 96ul
-> private_key:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h expanded_keys /\ live h private_key /\ disjoint expanded_keys private_key)
(ensures fun h0 _ h1 -> modifies (loc expanded_keys) h0 h1 /\
(let public_key, s, prefix = Spec.Ed25519.expand_keys (as_seq h0 private_key) in
as_seq h1 (gsub expanded_keys 0ul 32ul) == public_key /\
as_seq h1 (gsub expanded_keys 32ul 32ul) == s /\
as_seq h1 (gsub expanded_keys 64ul 32ul) == prefix)) | val expand_keys:
expanded_keys:lbuffer uint8 96ul
-> private_key:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h expanded_keys /\ live h private_key /\ disjoint expanded_keys private_key)
(ensures fun h0 _ h1 -> modifies (loc expanded_keys) h0 h1 /\
(let public_key, s, prefix = Spec.Ed25519.expand_keys (as_seq h0 private_key) in
as_seq h1 (gsub expanded_keys 0ul 32ul) == public_key /\
as_seq h1 (gsub expanded_keys 32ul 32ul) == s /\
as_seq h1 (gsub expanded_keys 64ul 32ul) == prefix)) | let expand_keys expanded_keys private_key =
let public_key = sub expanded_keys 0ul 32ul in
let s_prefix = sub expanded_keys 32ul 64ul in
let s = sub expanded_keys 32ul 32ul in
secret_expand s_prefix private_key;
Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key s | {
"file_name": "code/ed25519/Hacl.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 46,
"start_col": 0,
"start_line": 41
} | module Hacl.Ed25519
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module S = Spec.Ed25519
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit
(requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret)
(ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\
(let a, prefix = S.secret_expand (as_seq h0 secret) in
as_seq h1 (gsub expanded 0ul 32ul) == a /\
as_seq h1 (gsub expanded 32ul 32ul) == prefix))
[@CInline]
let secret_expand expanded secret =
assert_norm (pow2 32 <= pow2 125 - 1);
Hacl.Streaming.SHA2.hash_512 expanded secret 32ul;
let h_low = sub expanded 0ul 32ul in
let h_low0 = h_low.( 0ul) in
let h_low31 = h_low.(31ul) in
h_low.( 0ul) <- h_low0 &. u8 0xf8;
h_low.(31ul) <- (h_low31 &. u8 127) |. u8 64
let secret_to_public public_key private_key =
push_frame ();
let expanded_secret = create 64ul (u8 0) in
secret_expand expanded_secret private_key;
let a = sub expanded_secret 0ul 32ul in
Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key a;
pop_frame () | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Impl.Ed25519.Verify.fst.checked",
"Hacl.Impl.Ed25519.Sign.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
expanded_keys: Lib.Buffer.lbuffer Lib.IntTypes.uint8 96ul ->
private_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Ed25519.Sign.point_mul_g_compress",
"Prims.unit",
"Hacl.Ed25519.secret_expand",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let expand_keys expanded_keys private_key =
| let public_key = sub expanded_keys 0ul 32ul in
let s_prefix = sub expanded_keys 32ul 64ul in
let s = sub expanded_keys 32ul 32ul in
secret_expand s_prefix private_key;
Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key s | false |
PulseTutorial.ImplicationAndForall.fst | PulseTutorial.ImplicationAndForall.can_update | val can_update : x: Pulse.Lib.GhostReference.ref Prims.int -> Pulse.Lib.Core.vprop | let can_update (x:GR.ref int) =
forall* u v. pts_to x #one_half u @==>
pts_to x v | {
"file_name": "share/steel/examples/pulse/by-example/PulseTutorial.ImplicationAndForall.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 25,
"end_line": 87,
"start_col": 0,
"start_line": 85
} | module PulseTutorial.ImplicationAndForall
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick.Util
open Pulse.Lib.Forall.Util
module I = Pulse.Lib.Stick.Util
module GR = Pulse.Lib.GhostReference
open GR
//regain_half$
let regain_half #a (x:GR.ref a) (v:a) =
pts_to x #one_half v @==> pts_to x v
//regain_half$
```pulse //intro_regain_half$
ghost
fn intro_regain_half (x:GR.ref int)
requires pts_to x 'v
ensures pts_to x #one_half 'v ** regain_half x 'v
{
ghost
fn aux ()
requires pts_to x #one_half 'v ** pts_to x #one_half 'v
ensures pts_to x 'v
{
GR.gather x;
};
GR.share x;
I.intro _ _ _ aux;
fold regain_half;
}
```
```pulse //use_regain_half$
ghost
fn use_regain_half (x:GR.ref int)
requires pts_to x #one_half 'v ** regain_half x 'v
ensures pts_to x 'v
{
unfold regain_half;
I.elim _ _;
}
```
//regain_half_q$
let regain_half_q #a (x:GR.ref a) =
forall* u. pts_to x #one_half u @==> pts_to x u
//regain_half_q$
module FA = Pulse.Lib.Forall.Util
```pulse //intro_regain_half_q$
ghost
fn intro_regain_half_q (x:GR.ref int)
requires pts_to x 'v
ensures pts_to x #one_half 'v ** regain_half_q x
{
ghost
fn aux1 (u:int)
requires pts_to x #one_half 'v ** pts_to x #one_half u
ensures pts_to x u
{
gather x;
};
GR.share x;
FA.intro_forall_imp _ _ _ aux1;
fold regain_half_q;
}
```
```pulse //use_regain_half_q$
ghost
fn use_regain_half_q (x:GR.ref int)
requires pts_to x #one_half 'u ** regain_half_q x
ensures pts_to x 'u
{
unfold regain_half_q;
FA.elim #_ #(fun u -> pts_to x #one_half u @==> pts_to x u) 'u;
I.elim _ _;
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.Util.fst.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.GhostReference.fsti.checked",
"Pulse.Lib.Forall.Util.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "PulseTutorial.ImplicationAndForall.fst"
} | [
{
"abbrev": false,
"full_module": "GR",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Forall.Util",
"short_module": "FA"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.GhostReference",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Lib.GhostReference",
"short_module": "GR"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Forall.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseTutorial",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseTutorial",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Lib.GhostReference.ref Prims.int -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.Lib.GhostReference.ref",
"Prims.int",
"Pulse.Lib.Forall.op_forall_Star",
"Pulse.Lib.Stick.op_At_Equals_Equals_Greater",
"Pulse.Lib.GhostReference.pts_to",
"Pulse.Lib.Core.one_half",
"PulseCore.FractionalPermission.full_perm",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | true | false | let can_update (x: GR.ref int) =
| forall* u v. pts_to x #one_half u @==> pts_to x v | false |
|
LowParse.Low.Writers.Instances.fst | LowParse.Low.Writers.Instances.serialize32_bounded_integer_ct | val serialize32_bounded_integer_ct
(i: U32.t{1 <= U32.v i /\ U32.v i <= 4})
(x: bounded_integer (U32.v i))
(b: B.buffer byte)
(pos: U32.t)
: HST.Stack unit
(requires (fun h -> B.live h b /\ U32.v pos + 4 <= B.length b))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` i)) h h' /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v i) ==
serialize (serialize_bounded_integer (U32.v i)) x)) | val serialize32_bounded_integer_ct
(i: U32.t{1 <= U32.v i /\ U32.v i <= 4})
(x: bounded_integer (U32.v i))
(b: B.buffer byte)
(pos: U32.t)
: HST.Stack unit
(requires (fun h -> B.live h b /\ U32.v pos + 4 <= B.length b))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` i)) h h' /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v i) ==
serialize (serialize_bounded_integer (U32.v i)) x)) | let serialize32_bounded_integer_ct
(i: U32.t { 1 <= U32.v i /\ U32.v i <= 4 })
(x: bounded_integer (U32.v i))
(b: B.buffer byte)
(pos: U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h b /\
U32.v pos + 4 <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` i)) h h' /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v i) == serialize (serialize_bounded_integer (U32.v i)) x
))
= let h = HST.get () in
let before = LE.load32_be_i b pos in
bounded_integer_prop_equiv (U32.v i) x;
let after = BF.uint32.BF.set_bitfield_gen before (8ul `U32.mul` (4ul `U32.sub` i)) 32ul x in
LE.store32_be_i b pos after;
let h' = HST.get () in
parse_bounded_integer_spec (U32.v i) (Seq.slice (B.as_seq h b) (U32.v pos) (B.length b));
E.n_to_be_be_to_n 4 (Seq.slice (Seq.slice (B.as_seq h b) (U32.v pos) (B.length b)) 0 4);
Seq.slice_slice (B.as_seq h b) (U32.v pos) (B.length b) 0 4;
Seq.slice_slice (B.as_seq h' b) (U32.v pos) (B.length b) 0 4;
E.slice_n_to_be_bitfield 4 (U32.v before) (U32.v i) 4;
E.slice_n_to_be_bitfield 4 (U32.v after) (U32.v i) 4;
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 4)) (U32.v i);
Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)) (U32.v i);
BF.get_bitfield_set_bitfield_other #32 (U32.v before) (8 `op_Multiply` (4 - U32.v i)) 32 (U32.v x) 0 (8 `op_Multiply` (4 - U32.v i));
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos + U32.v i) (B.length b)) (4 - U32.v i);
Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos + U32.v i) (B.length b)) (4 - U32.v i);
B.modifies_loc_buffer_from_to_intro b pos (pos `U32.add` i) B.loc_none h h';
E.slice_n_to_be_bitfield 4 (U32.v after) 0 (U32.v i);
BF.get_bitfield_set_bitfield_same #32 (U32.v before) (8 `op_Multiply` (4 - U32.v i)) 32 (U32.v x);
serialize_bounded_integer_spec (U32.v i) x | {
"file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 343,
"start_col": 0,
"start_line": 309
} | module LowParse.Low.Writers.Instances
include LowParse.Low.Writers
include LowParse.Low.Combinators
include LowParse.Low.Bytes
include LowParse.Low.BitSum
module HS = FStar.HyperStack
module B = LowStar.Buffer
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
inline_for_extraction
noextract
let swrite_weaken
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(k2: parser_kind)
(w1: swriter s1 h0 space_beyond sout pout_from0 {
(k2 `is_weaker_than` k1) /\
k2.parser_kind_subkind == Some ParserStrong
})
: Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq s1 (swvalue w1);
serialized_length_eq (serialize_weaken k2 s1) (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_weaken k2 p1 h sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_nondep_then'
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from ->
serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2);
serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2);
serialized_length_eq s1 (swvalue w1);
serialized_length_eq s2 (swvalue w2);
let pos1 = swrite w1 pout_from in
let pos2 = swrite w2 pos1 in
let h' = HST.get () in
valid_nondep_then h' p1 p2 sout pout_from;
pos2
)
let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2
inline_for_extraction
noextract
let swrite_nondep_then
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond1: nat)
(w1: swriter s1 h0 space_beyond1 sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(#space_beyond2: nat)
(w2: swriter s2 h0 space_beyond2 sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= [@inline_let]
let sbmax = space_beyond1 `max` space_beyond2 in
weaken_swriter w1 h0 sbmax pout_from0 `swrite_nondep_then'` weaken_swriter w2 h0 sbmax pout_from0
inline_for_extraction
noextract
let swrite_filter
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(cond: (t1 -> GTot bool))
(w1: swriter s1 h0 space_beyond sout pout_from0 { cond (swvalue w1) } )
: Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq (serialize_filter s1 cond) (swvalue w1);
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_filter h p1 cond sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_synth
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#t2: Type)
(f12: (t1 -> GTot t2))
(f21: (t2 -> GTot t1))
(prf: squash (
synth_injective f12 /\
synth_inverse f12 f21
))
: Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 {
swvalue w2 == f12 (swvalue w1) /\
swvalue w1 == f21 (swvalue w2)
})
= [@inline_let] let _ =
serialize_synth_eq p1 f12 s1 f21 () (f12 (swvalue w1));
synth_injective_synth_inverse_synth_inverse_recip f12 f21 ()
in
SWriter (Ghost.hide (f12 (swvalue w1))) (fun pout_from ->
serialized_length_eq (serialize_synth p1 f12 s1 f21 ()) (f12 (swvalue w1));
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_synth h p1 f12 sout pout_from;
res
)
module U8 = FStar.UInt8
module FB = FStar.Bytes
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let swrite_flbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(len: U32.t)
(b: B.buffer U8.t {
B.live h0 b /\
B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_flbytes (U32.v len)) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_flbytes (U32.v len)) (FB.hide (B.as_seq h0 b));
let payload = B.sub sout.base pout_from len in
B.blit b 0ul payload 0ul len;
let h = HST.get () in
valid_flbytes_intro h (U32.v len) sout pout_from;
pout_from `U32.add` len
)
inline_for_extraction
noextract
let swrite_bounded_vlbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(len: U32.t { min <= U32.v len /\ U32.v len <= max })
(b: B.buffer U8.t {
B.length b == U32.v len /\
B.live h0 b /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_bounded_vlbytes min max) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_bounded_vlbytes min max) (FB.hide (B.as_seq h0 b));
length_serialize_bounded_vlbytes min max (FB.hide (B.as_seq h0 b));
let pout_payload = pout_from `U32.add` U32.uint_to_t (log256' max) in
let payload = B.sub sout.base pout_payload len in
B.blit b 0ul payload 0ul len;
finalize_bounded_vlbytes min max sout pout_from len
)
inline_for_extraction
noextract
let swrite_bounded_vlgenbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(#kk: parser_kind)
(#pk: parser kk (bounded_int32 min max))
(#sk: serializer pk { kk.parser_kind_subkind == Some ParserStrong })
(wk: leaf_writer_strong sk)
(len: U32.t { min <= U32.v len /\ U32.v len <= max })
(b: B.buffer U8.t {
B.live h0 b /\
B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_bounded_vlgenbytes min max sk) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_bounded_vlgenbytes min max sk) (FB.hide (B.as_seq h0 b));
length_serialize_bounded_vlgenbytes min max sk (FB.hide (B.as_seq h0 b));
serialized_length_eq sk len;
let pout_payload = swrite (swrite_leaf wk h0 sout pout_from0 len) pout_from in
let payload = B.sub sout.base pout_payload len in
B.blit b 0ul payload 0ul len;
let h = HST.get () in
valid_bounded_vlgenbytes min max pk sout pout_from h;
pout_payload `U32.add` len
)
#pop-options
#push-options "--z3rlimit 32"
inline_for_extraction
noextract
let swrite_bitsum
(h0: HS.mem)
(space_beyond: nat)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(#kt: parser_kind)
(#tot: pos)
(#t: eqtype)
(#cl: uint_t tot t)
(b: bitsum' cl tot)
(#data: Type)
(tag_of_data: (data -> Tot (bitsum'_type b)))
(type_of_tag: (bitsum'_key_type b -> Tot Type))
(synth_case: synth_case_t b data tag_of_data type_of_tag)
(#p: parser kt t)
(#s: serializer p { kt.parser_kind_subkind == Some ParserStrong } )
(w_tg: leaf_writer_strong s)
(mk: synth_bitsum'_recip_t b)
(#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x)))
(g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x))))
(k: bitsum'_type b {
(parse_bitsum_kind kt b type_of_tag f).parser_kind_subkind == Some ParserStrong /\
(dfst (f (bitsum'_key_of_t b k))).parser_kind_subkind == Some ParserStrong
})
(w_pl: swriter (g (bitsum'_key_of_t b k)) h0 space_beyond sout pout_from0)
: Tot (w' : swriter (serialize_bitsum b tag_of_data type_of_tag synth_case s #f g) h0 space_beyond sout pout_from0 {
swvalue w' == synth_case.f k (swvalue w_pl)
})
= SWriter (Ghost.hide (synth_case.f k (swvalue w_pl))) (fun pout_from ->
serialized_length_eq (serialize_bitsum b tag_of_data type_of_tag synth_case s #f g) (synth_case.f k (swvalue w_pl));
serialized_length_eq s (synth_bitsum'_recip b k);
serialized_length_eq (g (bitsum'_key_of_t b k)) (swvalue w_pl);
serialize_bitsum_eq_2 b tag_of_data type_of_tag synth_case s g k (swvalue w_pl);
let pos1 = w_tg (mk k) sout pout_from in
let pos2 = swrite w_pl pos1 in
let h = HST.get () in
valid_filter h p (filter_bitsum' b) sout pout_from;
synth_bitsum'_injective b;
synth_bitsum'_recip_inverse b;
assert (filter_bitsum' b (mk k) == true);
assert (synth_bitsum' b (mk k) == k);
valid_synth h (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) sout pout_from;
valid_bitsum_intro b tag_of_data type_of_tag synth_case p f h sout pout_from;
pos2
)
#pop-options
module BF = LowParse.BitFields
module E = LowParse.Endianness.BitFields
module LE = LowStar.Endianness
#push-options "--z3rlimit 16" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Endianness.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Low.Writers.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.Bytes.fst.checked",
"LowParse.Low.BitSum.fst.checked",
"LowParse.Endianness.BitFields.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Writers.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Endianness",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "LowParse.Endianness.BitFields",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "FB"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowParse.Low.BitSum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: FStar.UInt32.t{1 <= FStar.UInt32.v i /\ FStar.UInt32.v i <= 4} ->
x: LowParse.Spec.BoundedInt.bounded_integer (FStar.UInt32.v i) ->
b: LowStar.Buffer.buffer LowParse.Bytes.byte ->
pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowStar.Buffer.buffer",
"LowParse.Bytes.byte",
"LowParse.Spec.BoundedInt.serialize_bounded_integer_spec",
"Prims.unit",
"LowParse.BitFields.get_bitfield_set_bitfield_same",
"Prims.op_Multiply",
"Prims.op_Subtraction",
"LowParse.Endianness.BitFields.slice_n_to_be_bitfield",
"LowStar.Monotonic.Buffer.modifies_loc_buffer_from_to_intro",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.add",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Seq.Properties.lemma_split",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.op_Addition",
"LowStar.Monotonic.Buffer.length",
"LowParse.BitFields.get_bitfield_set_bitfield_other",
"FStar.Seq.Properties.slice_slice",
"FStar.Endianness.n_to_be_be_to_n",
"LowParse.Spec.BoundedInt.parse_bounded_integer_spec",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.Endianness.store32_be_i",
"Prims.eq2",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.uint32",
"LowParse.BitFields.set_bitfield",
"FStar.UInt32.mul",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.sub",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield_gen",
"FStar.UInt32.__uint_to_t",
"LowParse.Spec.BoundedInt.bounded_integer_prop_equiv",
"LowStar.Endianness.u32",
"LowStar.Endianness.load32_be_i",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"FStar.Seq.Base.seq",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.BoundedInt.serialize_bounded_integer"
] | [] | false | true | false | false | false | let serialize32_bounded_integer_ct
(i: U32.t{1 <= U32.v i /\ U32.v i <= 4})
(x: bounded_integer (U32.v i))
(b: B.buffer byte)
(pos: U32.t)
: HST.Stack unit
(requires (fun h -> B.live h b /\ U32.v pos + 4 <= B.length b))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` i)) h h' /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v i) ==
serialize (serialize_bounded_integer (U32.v i)) x)) =
| let h = HST.get () in
let before = LE.load32_be_i b pos in
bounded_integer_prop_equiv (U32.v i) x;
let after = BF.uint32.BF.set_bitfield_gen before (8ul `U32.mul` (4ul `U32.sub` i)) 32ul x in
LE.store32_be_i b pos after;
let h' = HST.get () in
parse_bounded_integer_spec (U32.v i) (Seq.slice (B.as_seq h b) (U32.v pos) (B.length b));
E.n_to_be_be_to_n 4 (Seq.slice (Seq.slice (B.as_seq h b) (U32.v pos) (B.length b)) 0 4);
Seq.slice_slice (B.as_seq h b) (U32.v pos) (B.length b) 0 4;
Seq.slice_slice (B.as_seq h' b) (U32.v pos) (B.length b) 0 4;
E.slice_n_to_be_bitfield 4 (U32.v before) (U32.v i) 4;
E.slice_n_to_be_bitfield 4 (U32.v after) (U32.v i) 4;
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 4)) (U32.v i);
Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + 4)) (U32.v i);
BF.get_bitfield_set_bitfield_other #32
(U32.v before)
(8 `op_Multiply` (4 - U32.v i))
32
(U32.v x)
0
(8 `op_Multiply` (4 - U32.v i));
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos + U32.v i) (B.length b)) (4 - U32.v i);
Seq.lemma_split (Seq.slice (B.as_seq h b) (U32.v pos + U32.v i) (B.length b)) (4 - U32.v i);
B.modifies_loc_buffer_from_to_intro b pos (pos `U32.add` i) B.loc_none h h';
E.slice_n_to_be_bitfield 4 (U32.v after) 0 (U32.v i);
BF.get_bitfield_set_bitfield_same #32 (U32.v before) (8 `op_Multiply` (4 - U32.v i)) 32 (U32.v x);
serialize_bounded_integer_spec (U32.v i) x | false |
LowParse.Low.Writers.Instances.fst | LowParse.Low.Writers.Instances.swrite_flbytes | val swrite_flbytes
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0 len: U32.t)
(b:
B.buffer U8.t
{ B.live h0 b /\ B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0) })
: Tot
(w:
swriter (serialize_flbytes (U32.v len)) h0 0 sout pout_from0
{swvalue w == FB.hide (B.as_seq h0 b)}) | val swrite_flbytes
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0 len: U32.t)
(b:
B.buffer U8.t
{ B.live h0 b /\ B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0) })
: Tot
(w:
swriter (serialize_flbytes (U32.v len)) h0 0 sout pout_from0
{swvalue w == FB.hide (B.as_seq h0 b)}) | let swrite_flbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(len: U32.t)
(b: B.buffer U8.t {
B.live h0 b /\
B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_flbytes (U32.v len)) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_flbytes (U32.v len)) (FB.hide (B.as_seq h0 b));
let payload = B.sub sout.base pout_from len in
B.blit b 0ul payload 0ul len;
let h = HST.get () in
valid_flbytes_intro h (U32.v len) sout pout_from;
pout_from `U32.add` len
) | {
"file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 187,
"start_col": 0,
"start_line": 167
} | module LowParse.Low.Writers.Instances
include LowParse.Low.Writers
include LowParse.Low.Combinators
include LowParse.Low.Bytes
include LowParse.Low.BitSum
module HS = FStar.HyperStack
module B = LowStar.Buffer
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
inline_for_extraction
noextract
let swrite_weaken
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(k2: parser_kind)
(w1: swriter s1 h0 space_beyond sout pout_from0 {
(k2 `is_weaker_than` k1) /\
k2.parser_kind_subkind == Some ParserStrong
})
: Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq s1 (swvalue w1);
serialized_length_eq (serialize_weaken k2 s1) (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_weaken k2 p1 h sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_nondep_then'
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from ->
serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2);
serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2);
serialized_length_eq s1 (swvalue w1);
serialized_length_eq s2 (swvalue w2);
let pos1 = swrite w1 pout_from in
let pos2 = swrite w2 pos1 in
let h' = HST.get () in
valid_nondep_then h' p1 p2 sout pout_from;
pos2
)
let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2
inline_for_extraction
noextract
let swrite_nondep_then
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond1: nat)
(w1: swriter s1 h0 space_beyond1 sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(#space_beyond2: nat)
(w2: swriter s2 h0 space_beyond2 sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= [@inline_let]
let sbmax = space_beyond1 `max` space_beyond2 in
weaken_swriter w1 h0 sbmax pout_from0 `swrite_nondep_then'` weaken_swriter w2 h0 sbmax pout_from0
inline_for_extraction
noextract
let swrite_filter
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(cond: (t1 -> GTot bool))
(w1: swriter s1 h0 space_beyond sout pout_from0 { cond (swvalue w1) } )
: Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq (serialize_filter s1 cond) (swvalue w1);
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_filter h p1 cond sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_synth
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#t2: Type)
(f12: (t1 -> GTot t2))
(f21: (t2 -> GTot t1))
(prf: squash (
synth_injective f12 /\
synth_inverse f12 f21
))
: Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 {
swvalue w2 == f12 (swvalue w1) /\
swvalue w1 == f21 (swvalue w2)
})
= [@inline_let] let _ =
serialize_synth_eq p1 f12 s1 f21 () (f12 (swvalue w1));
synth_injective_synth_inverse_synth_inverse_recip f12 f21 ()
in
SWriter (Ghost.hide (f12 (swvalue w1))) (fun pout_from ->
serialized_length_eq (serialize_synth p1 f12 s1 f21 ()) (f12 (swvalue w1));
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_synth h p1 f12 sout pout_from;
res
)
module U8 = FStar.UInt8
module FB = FStar.Bytes
#push-options "--z3rlimit 16"
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Endianness.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Low.Writers.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.Bytes.fst.checked",
"LowParse.Low.BitSum.fst.checked",
"LowParse.Endianness.BitFields.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Writers.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "FB"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowParse.Low.BitSum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: FStar.Monotonic.HyperStack.mem ->
sout:
LowParse.Slice.slice (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte
))
(LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte)) ->
pout_from0: FStar.UInt32.t ->
len: FStar.UInt32.t ->
b:
LowStar.Buffer.buffer FStar.UInt8.t
{ LowStar.Monotonic.Buffer.live h0 b /\
LowStar.Monotonic.Buffer.length b == FStar.UInt32.v len /\
LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer b)
(LowParse.Slice.loc_slice_from sout pout_from0) }
-> w:
LowParse.Low.Writers.swriter (LowParse.Spec.Bytes.serialize_flbytes (FStar.UInt32.v len))
h0
0
sout
pout_from0
{LowParse.Low.Writers.swvalue w == FStar.Bytes.hide (LowStar.Monotonic.Buffer.as_seq h0 b)} | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"LowParse.Slice.srel_of_buffer_srel",
"LowParse.Bytes.byte",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.t",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowParse.Slice.loc_slice_from",
"LowParse.Low.Writers.SWriter",
"LowParse.Spec.Base.total_constant_size_parser_kind",
"FStar.Bytes.lbytes",
"LowParse.Spec.Bytes.parse_flbytes",
"LowParse.Spec.Bytes.serialize_flbytes",
"FStar.Ghost.hide",
"FStar.Bytes.hide",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt32.add",
"Prims.unit",
"LowParse.Low.Bytes.valid_flbytes_intro",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.blit",
"FStar.UInt32.__uint_to_t",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.Buffer.sub",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Writers.swriter",
"FStar.Bytes.bytes",
"LowParse.Low.Writers.swvalue"
] | [] | false | false | false | false | false | let swrite_flbytes
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0 len: U32.t)
(b:
B.buffer U8.t
{ B.live h0 b /\ B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0) })
: Tot
(w:
swriter (serialize_flbytes (U32.v len)) h0 0 sout pout_from0
{swvalue w == FB.hide (B.as_seq h0 b)}) =
| SWriter (Ghost.hide (FB.hide (B.as_seq h0 b)))
(fun pout_from ->
serialized_length_eq (serialize_flbytes (U32.v len)) (FB.hide (B.as_seq h0 b));
let payload = B.sub sout.base pout_from len in
B.blit b 0ul payload 0ul len;
let h = HST.get () in
valid_flbytes_intro h (U32.v len) sout pout_from;
pout_from `U32.add` len) | false |
Sec2.HIFC.fst | Sec2.HIFC.loc | val loc : Prims.eqtype | let loc = int | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 4,
"start_col": 0,
"start_line": 4
} | module Sec2.HIFC
open FStar.List.Tot | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"Prims.int"
] | [] | false | false | false | true | false | let loc =
| int | false |
|
Hacl.HPKE.Interface.AEAD.fst | Hacl.HPKE.Interface.AEAD.aead_encrypt_cp256 | val aead_encrypt_cp256 : aead_encrypt_st (S.Seal AEAD.CHACHA20_POLY1305) | val aead_encrypt_cp256 : aead_encrypt_st (S.Seal AEAD.CHACHA20_POLY1305) | let aead_encrypt_cp256 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_256.encrypt cipher tag input len aad alen key nonce | {
"file_name": "code/hpke/Hacl.HPKE.Interface.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 53,
"start_col": 0,
"start_line": 49
} | module Hacl.HPKE.Interface.AEAD
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.Buffer
friend Spec.Agile.AEAD
/// These two functions will never be extracted, they are only an interface
/// boundary for the tactic performing instantiations.
/// In other files, it is exposed as an assume val, but for AEAD, we need an fsti
/// since we need to friend Spec.Agile.AEAD to perform the instantiations below,
/// and assume val are forbidden in interface files
let aead_encrypt #cs = admit()
let aead_decrypt #cs = admit()
#set-options "--z3rlimit 60 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let aead_encrypt_cp32 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_32.encrypt cipher tag input len aad alen key nonce
inline_for_extraction noextract
let aead_decrypt_cp32 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_32.decrypt input cipher len aad alen key nonce tag
inline_for_extraction noextract
let aead_encrypt_cp128 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_128.encrypt cipher tag input len aad alen key nonce
inline_for_extraction noextract
let aead_decrypt_cp128 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_128.decrypt input cipher len aad alen key nonce tag | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Chacha20Poly1305_32.fst.checked",
"Hacl.Chacha20Poly1305_256.fst.checked",
"Hacl.Chacha20Poly1305_128.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.Interface.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.HPKE.Interface.AEAD.aead_encrypt_st (Spec.Agile.HPKE.Seal Spec.Agile.AEAD.CHACHA20_POLY1305) | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.l_and",
"Prims.b2t",
"Spec.Agile.HPKE.uu___is_Seal",
"Spec.Agile.HPKE.Seal",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"Spec.Agile.HPKE.is_valid_aead",
"Hacl.HPKE.Interface.AEAD.kv",
"Spec.Agile.HPKE.__proj__Seal__item__alg",
"Hacl.HPKE.Interface.AEAD.iv",
"Lib.IntTypes.size_t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Agile.AEAD.max_length",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.size",
"Hacl.Chacha20Poly1305_256.encrypt",
"Prims.unit",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let aead_encrypt_cp256 =
| fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_256.encrypt cipher tag input len aad alen key nonce | false |
Hacl.FFDHE.fst | Hacl.FFDHE.ffdhe_len | val ffdhe_len (a: S.ffdhe_alg) : DH.size_pos | val ffdhe_len (a: S.ffdhe_alg) : DH.size_pos | let ffdhe_len (a:S.ffdhe_alg) : DH.size_pos = DH.ffdhe_len a | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private
[@CInline]
let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a)
private
[@CInline]
let ffdhe_check_pk (a:S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a)
private
[@CInline]
let ffdhe_compute_exp (a:S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_compute_exp a (DH.ffdhe_len a) (ke a) | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg -> Hacl.Impl.FFDHE.size_pos | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Impl.FFDHE.ffdhe_len",
"Hacl.Impl.FFDHE.size_pos"
] | [] | false | false | false | true | false | let ffdhe_len (a: S.ffdhe_alg) : DH.size_pos =
| DH.ffdhe_len a | false |
Hacl.FFDHE.fst | Hacl.FFDHE.t_limbs | val t_limbs : Lib.IntTypes.inttype | let t_limbs = U64 | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.IntTypes.inttype | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.U64"
] | [] | false | false | false | true | false | let t_limbs =
| U64 | false |
|
LowParse.Low.Writers.Instances.fst | LowParse.Low.Writers.Instances.swrite_bounded_vlbytes | val swrite_bounded_vlbytes
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(len: U32.t{min <= U32.v len /\ U32.v len <= max})
(b:
B.buffer U8.t
{ B.length b == U32.v len /\ B.live h0 b /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0) })
: Tot
(w:
swriter (serialize_bounded_vlbytes min max) h0 0 sout pout_from0
{swvalue w == FB.hide (B.as_seq h0 b)}) | val swrite_bounded_vlbytes
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(len: U32.t{min <= U32.v len /\ U32.v len <= max})
(b:
B.buffer U8.t
{ B.length b == U32.v len /\ B.live h0 b /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0) })
: Tot
(w:
swriter (serialize_bounded_vlbytes min max) h0 0 sout pout_from0
{swvalue w == FB.hide (B.as_seq h0 b)}) | let swrite_bounded_vlbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 })
(len: U32.t { min <= U32.v len /\ U32.v len <= max })
(b: B.buffer U8.t {
B.length b == U32.v len /\
B.live h0 b /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_bounded_vlbytes min max) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_bounded_vlbytes min max) (FB.hide (B.as_seq h0 b));
length_serialize_bounded_vlbytes min max (FB.hide (B.as_seq h0 b));
let pout_payload = pout_from `U32.add` U32.uint_to_t (log256' max) in
let payload = B.sub sout.base pout_payload len in
B.blit b 0ul payload 0ul len;
finalize_bounded_vlbytes min max sout pout_from len
) | {
"file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 213,
"start_col": 0,
"start_line": 191
} | module LowParse.Low.Writers.Instances
include LowParse.Low.Writers
include LowParse.Low.Combinators
include LowParse.Low.Bytes
include LowParse.Low.BitSum
module HS = FStar.HyperStack
module B = LowStar.Buffer
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
inline_for_extraction
noextract
let swrite_weaken
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(k2: parser_kind)
(w1: swriter s1 h0 space_beyond sout pout_from0 {
(k2 `is_weaker_than` k1) /\
k2.parser_kind_subkind == Some ParserStrong
})
: Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq s1 (swvalue w1);
serialized_length_eq (serialize_weaken k2 s1) (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_weaken k2 p1 h sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_nondep_then'
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(w2: swriter s2 h0 space_beyond sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from ->
serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2);
serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2);
serialized_length_eq s1 (swvalue w1);
serialized_length_eq s2 (swvalue w2);
let pos1 = swrite w1 pout_from in
let pos2 = swrite w2 pos1 in
let h' = HST.get () in
valid_nondep_then h' p1 p2 sout pout_from;
pos2
)
let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2
inline_for_extraction
noextract
let swrite_nondep_then
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond1: nat)
(w1: swriter s1 h0 space_beyond1 sout pout_from0)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong })
(#space_beyond2: nat)
(w2: swriter s2 h0 space_beyond2 sout pout_from0)
: Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 {
swvalue w == (swvalue w1, swvalue w2)
})
= [@inline_let]
let sbmax = space_beyond1 `max` space_beyond2 in
weaken_swriter w1 h0 sbmax pout_from0 `swrite_nondep_then'` weaken_swriter w2 h0 sbmax pout_from0
inline_for_extraction
noextract
let swrite_filter
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(cond: (t1 -> GTot bool))
(w1: swriter s1 h0 space_beyond sout pout_from0 { cond (swvalue w1) } )
: Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 {
swvalue w2 == swvalue w1
})
= SWriter (Ghost.hide (swvalue w1)) (fun pout_from ->
serialized_length_eq (serialize_filter s1 cond) (swvalue w1);
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_filter h p1 cond sout pout_from;
res
)
inline_for_extraction
noextract
let swrite_synth
(#h0: HS.mem)
(#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(#pout_from0: U32.t)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong })
(#space_beyond: nat)
(w1: swriter s1 h0 space_beyond sout pout_from0)
(#t2: Type)
(f12: (t1 -> GTot t2))
(f21: (t2 -> GTot t1))
(prf: squash (
synth_injective f12 /\
synth_inverse f12 f21
))
: Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 {
swvalue w2 == f12 (swvalue w1) /\
swvalue w1 == f21 (swvalue w2)
})
= [@inline_let] let _ =
serialize_synth_eq p1 f12 s1 f21 () (f12 (swvalue w1));
synth_injective_synth_inverse_synth_inverse_recip f12 f21 ()
in
SWriter (Ghost.hide (f12 (swvalue w1))) (fun pout_from ->
serialized_length_eq (serialize_synth p1 f12 s1 f21 ()) (f12 (swvalue w1));
serialized_length_eq s1 (swvalue w1);
let res = swrite w1 pout_from in
let h = HST.get () in
valid_synth h p1 f12 sout pout_from;
res
)
module U8 = FStar.UInt8
module FB = FStar.Bytes
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let swrite_flbytes
(h0: HS.mem)
(sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(len: U32.t)
(b: B.buffer U8.t {
B.live h0 b /\
B.length b == U32.v len /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0)
})
: Tot (w: swriter (serialize_flbytes (U32.v len)) h0 0 sout pout_from0 {
swvalue w == FB.hide (B.as_seq h0 b)
})
= SWriter (Ghost.hide (FB.hide (B.as_seq h0 b))) (fun pout_from ->
serialized_length_eq (serialize_flbytes (U32.v len)) (FB.hide (B.as_seq h0 b));
let payload = B.sub sout.base pout_from len in
B.blit b 0ul payload 0ul len;
let h = HST.get () in
valid_flbytes_intro h (U32.v len) sout pout_from;
pout_from `U32.add` len
)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Endianness.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Low.Writers.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.Bytes.fst.checked",
"LowParse.Low.BitSum.fst.checked",
"LowParse.Endianness.BitFields.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Bytes.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Writers.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Bytes",
"short_module": "FB"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "LowParse.Low.BitSum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Writers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: FStar.Monotonic.HyperStack.mem ->
sout:
LowParse.Slice.slice (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte
))
(LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte)) ->
pout_from0: FStar.UInt32.t ->
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
len: FStar.UInt32.t{min <= FStar.UInt32.v len /\ FStar.UInt32.v len <= max} ->
b:
LowStar.Buffer.buffer FStar.UInt8.t
{ LowStar.Monotonic.Buffer.length b == FStar.UInt32.v len /\
LowStar.Monotonic.Buffer.live h0 b /\
LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer b)
(LowParse.Slice.loc_slice_from sout pout_from0) }
-> w:
LowParse.Low.Writers.swriter (LowParse.Spec.Bytes.serialize_bounded_vlbytes min max)
h0
0
sout
pout_from0
{LowParse.Low.Writers.swvalue w == FStar.Bytes.hide (LowStar.Monotonic.Buffer.as_seq h0 b)} | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"LowParse.Slice.srel_of_buffer_srel",
"LowParse.Bytes.byte",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"FStar.UInt32.v",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowParse.Slice.loc_slice_from",
"LowParse.Low.Writers.SWriter",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.Bytes.parse_all_bytes_kind",
"LowParse.Spec.Bytes.parse_bounded_vlbytes_t",
"LowParse.Spec.Bytes.parse_bounded_vlbytes",
"LowParse.Spec.Bytes.serialize_bounded_vlbytes",
"FStar.Ghost.hide",
"FStar.Bytes.hide",
"LowStar.Monotonic.Buffer.as_seq",
"LowParse.Low.Bytes.finalize_bounded_vlbytes",
"Prims.unit",
"LowStar.Monotonic.Buffer.blit",
"FStar.UInt32.__uint_to_t",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.Buffer.sub",
"LowParse.Slice.__proj__Mkslice__item__base",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Spec.Bytes.length_serialize_bounded_vlbytes",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Writers.swriter",
"FStar.Bytes.bytes",
"LowParse.Low.Writers.swvalue"
] | [] | false | false | false | false | false | let swrite_bounded_vlbytes
(h0: HS.mem)
(sout:
slice (srel_of_buffer_srel (B.trivial_preorder _))
(srel_of_buffer_srel (B.trivial_preorder _)))
(pout_from0: U32.t)
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(len: U32.t{min <= U32.v len /\ U32.v len <= max})
(b:
B.buffer U8.t
{ B.length b == U32.v len /\ B.live h0 b /\
B.loc_disjoint (B.loc_buffer b) (loc_slice_from sout pout_from0) })
: Tot
(w:
swriter (serialize_bounded_vlbytes min max) h0 0 sout pout_from0
{swvalue w == FB.hide (B.as_seq h0 b)}) =
| SWriter (Ghost.hide (FB.hide (B.as_seq h0 b)))
(fun pout_from ->
serialized_length_eq (serialize_bounded_vlbytes min max) (FB.hide (B.as_seq h0 b));
length_serialize_bounded_vlbytes min max (FB.hide (B.as_seq h0 b));
let pout_payload = pout_from `U32.add` (U32.uint_to_t (log256' max)) in
let payload = B.sub sout.base pout_payload len in
B.blit b 0ul payload 0ul len;
finalize_bounded_vlbytes min max sout pout_from len) | false |
Sec2.HIFC.fst | Sec2.HIFC.sel | val sel (s: store) (l: loc) : int | val sel (s: store) (l: loc) : int | let sel (s:store) (l:loc) : int = Map.sel s l | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 7,
"start_col": 0,
"start_line": 7
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: Sec2.HIFC.store -> l: Sec2.HIFC.loc -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.store",
"Sec2.HIFC.loc",
"FStar.Map.sel",
"Prims.int"
] | [] | false | false | false | true | false | let sel (s: store) (l: loc) : int =
| Map.sel s l | false |
Sec2.HIFC.fst | Sec2.HIFC.pre | val pre : Type | let pre = store -> Type0 | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 11,
"start_col": 0,
"start_line": 11
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | Type | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.store"
] | [] | false | false | false | true | true | let pre =
| store -> Type0 | false |
|
Sec2.HIFC.fst | Sec2.HIFC.hst | val hst : a: Type -> p: Sec2.HIFC.pre -> q: Sec2.HIFC.post a -> Type | let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)} | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 84,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> p: Sec2.HIFC.pre -> q: Sec2.HIFC.post a -> Type | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.store",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | true | true | let hst a (p: pre) (q: post a) =
| s0: store{p s0} -> r: (a & store){q s0 (fst r) (snd r)} | false |
|
PulseCore.Preorder.fst | PulseCore.Preorder.pcm_history_induces_preorder | val pcm_history_induces_preorder (#a #p: _)
: Lemma (induces_preorder (pcm_history #a #p) (pcm_history_preorder #a #p)) | val pcm_history_induces_preorder (#a #p: _)
: Lemma (induces_preorder (pcm_history #a #p) (pcm_history_preorder #a #p)) | let pcm_history_induces_preorder #a #p
: Lemma (induces_preorder (pcm_history #a #p)
(pcm_history_preorder #a #p))
= let aux (x y:history a p)
(f:frame_preserving_upd (pcm_history #a #p) x y)
(v:history a p)
: Lemma
(requires compatible (pcm_history #a #p) x v)
(ensures (pcm_history_preorder #a #p) v (f v))
[SMTPat ()]
= let pcm = pcm_history #a #p in
let v1 = f v in
match x, v, v1 with
| Witnessed _, Witnessed _, Witnessed _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Witnessed _ -> ()
| Witnessed _, Current _ _, Witnessed _ -> ()
| Witnessed _, Witnessed _, Current _ _ ->
assert (composable pcm x v)
| Current _ _, Witnessed _, Current _ _ -> ()
| Witnessed _, Current _ _, Current _ _ -> ()
| Current hx _, Current hv _, Witnessed _
| Current hx _, Current hv _, Current _ _ ->
let frame = FStar.IndefiniteDescription.indefinite_description_ghost
(history a p) (fun frame -> composable pcm x frame /\ op pcm frame x == v) in
match frame with
| Current hf _ -> ()
| Witnessed hf ->
assert (extends hx hf);
assert (hx == hv);
assert (composable pcm x (Witnessed hv))
in
() | {
"file_name": "lib/pulse_core/PulseCore.Preorder.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 409,
"start_col": 0,
"start_line": 377
} | (*
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 PulseCore.Preorder
open FStar.PCM
open FStar.Preorder
open PulseCore.FractionalPermission
open FStar.Real
/// This module explores the connection between PCM and preorders. More specifically, we show here
/// that any PCM induces a preorder relation, characterized by frame-preservation for any updates.
///
/// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder,
/// by taking as elements of the PCM the trace of all the states of the element.
(**** PCM to preoder *)
(**
PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y],
the argument and result of the frame preserving update are related by q
*)
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) =
forall (x y:a) (f:frame_preserving_upd p x y) (v:a).
p.refine v ==> compatible p x v ==> q v (f v)
(**
We can define a canonical preorder from any PCM by taking the quantified conjunction over all the
preorders [q] induced by this PCM.
*)
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a =
fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a)
(x y:a) (f:frame_preserving_upd p x y)
(v_old:a{p.refine v_old /\ compatible p x v_old})
: Lemma ((preorder_of_pcm p) v_old (f v_old))
= ()
(**
This canonical preorder enjoys the nice property that it preserves fact stability of any
induced preorder
*)
let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a)
: Lemma
(requires stable fact q /\
induces_preorder p q)
(ensures stable fact (preorder_of_pcm p))
= ()
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a)
: Lemma
(requires
stable fact (preorder_of_pcm p) /\
p.refine v0 /\
fact v0 /\
p.refine v1 /\
frame_preserving p v v1 /\
compatible p v v0)
(ensures
fact v1)
= let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in
frame_preserving_upd_is_preorder_preserving p v v1 f v0
(**** Preorder to PCM *)
(***** Building the preorder *)
(**
This predicate tells that the list [l] can represent a trace of elements whose evolution is
compatible with the preorder [q]
*)
let rec qhistory #a (q:preorder a) (l:list a) =
match l with
| []
| [_] -> True
| x::y::tl -> y `q` x /\ qhistory q (y::tl)
(** The history of a preorder is the type of all the traces compatible with that preorder *)
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
(** Two compatible traces can extend each other *)
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
(** This extension relation is transitive *)
let rec extends_trans #a (#q:preorder a) (x y z:hist q)
: Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z)
[SMTPat (x `extends'` y);
SMTPat (y `extends'` z)]
= match x with
| [] -> ()
| _::tl -> extends_trans tl y z
(** And it is also reflexive, so extensibility on traces is a preorder on traces *)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
module L = FStar.List.Tot
(** If [h0] extends by [h1], then the length of [h0] is superior *)
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q)
: Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1))
[SMTPat (extends h0 h1)]
= match h0 with
| [] -> ()
| hd::tl -> extends_length_eq tl h1
(**
We build our relation of composability for traces by reflexing the extension to ensure
symmetry
*)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
(** The operation for the PCM is to return the full trace of two extensible traces *)
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q =
if L.length x >= L.length y
then x
else if L.length x = L.length y
then (assert (x == y); x)
else y
(** The operation actually implements extension *)
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (ensures (p_op q x y `extends` x /\
p_op q x y `extends` y /\
(p_op q x y == x \/ p_op q x y == y)))
[SMTPat (p_op q x y)]
= extends_length_eq x y;
extends_length_eq y x
(** And the empty trace is the unit element *)
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q)
: Lemma (ensures (p_composable q x [] /\ p_op q x [] == x))
[SMTPat (p_composable q x [])]
= match x with
| [] -> ()
| _::tl -> p_op_nil q tl
(** We can finally define our PCM with these operations *)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = {
composable = p_composable q;
op = p_op q;
one = []
}
(** Composability is commutative *)
let comm (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires p_composable q x y)
(ensures p_composable q y x)
= ()
(** As well as the compose operation *)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y})
: Lemma (p_op q x y == p_op q y x)
= extends_length_eq x y;
extends_length_eq y x
(** If [z] extends [x] and [y], then [x] and [y] are extending one or another *)
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q)
: Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x)
[SMTPat (z `extends` x);
SMTPat (z `extends` y)]
= match z with
| [] -> ()
| _::tl -> extends_disjunction x y tl
(** If [x] extends [y], then the two heads of the traces are still related by the preorder *)
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q)
: Lemma
(ensures
x `extends` y /\
Cons? x /\
Cons? y ==> Cons?.hd y `q` Cons?.hd x)
[SMTPat (x `extends` y)]
= match x with
| [] -> ()
| _::tl -> extends_related_head tl y
(** Finally, we can have our fully-fledged PCM from the preorder *)
let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = {
p = p q;
comm = comm_op q;
assoc = (fun _ _ _ -> ());
assoc_r = (fun _ _ _ -> ());
is_unit = (fun _ -> ());
refine = (fun _ -> True)
}
(***** Using the preorder *)
(**
We check that the preorder derived from the PCM derived from the preorder
satisfies the same properties as the original preorder. Here, we get back history
extension from frame-preserving updates.
*)
let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q)
: Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z))
(ensures (y `extends` z))
= ()
(** A non-empty history *)
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
(** Get the current value from an history *)
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
(**
Given a frame-preserving update from [x] to [y]
for any value of resource [z] (compatible with [x])
the new value [y] advances the history [z] in a preorder respecting manner
*)
let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y))
= ()
(** Still given a frame-preserving update from [x] to [y], this update extends the history *)
let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z))
= ()
(** Helper function that flips a preoder *)
let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x
(**
What is the preorder induced from the PCM induced by preorder [q]? It turns out that
it is the flipped of [q], reversed extension.
*)
let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q)
: Lemma (requires frame_preserving (pcm_of_preorder q) x y)
(ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y))
[SMTPat (frame_preserving (pcm_of_preorder q) x y)]
= ()
#push-options "--warn_error -271"
let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a)
: Lemma (induces_preorder (pcm_of_preorder q) (flip extends))
= let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q)
: Lemma (requires compatible (pcm_of_preorder q) x v)
(ensures extends (f v) v)
[SMTPat ()]
= assert (composable (pcm_of_preorder q) x v) in
()
#pop-options
let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v})
: h1:vhist q{h1 `extends` h0}
= v :: h0
let property (a:Type)
= a -> prop
let stable_property (#a:Type) (pcm:pcm a)
= fact:property a {
FStar.Preorder.stable fact (preorder_of_pcm pcm)
}
let fact_valid_compat (#a:Type) (#pcm:pcm a)
(fact:stable_property pcm)
(v:a)
= forall z. compatible pcm v z ==> fact z
noeq
type history (a:Type) (p:preorder a) =
| Witnessed : hist p -> history a p
| Current : h:vhist p -> f:perm -> history a p
let hval_tot #a #p (h:history a p{Current? h}) : a =
match h with
| Current h _ -> curval h
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a =
hval_tot h
let hperm #a #p (h:history a p{Current? h}) : perm =
match h with
| Current _ f -> f
let history_composable #a #p
: symrel (history a p)
= fun h0 h1 ->
match h0, h1 with
| Witnessed h0, Witnessed h1 ->
p_composable p h0 h1
| Witnessed h0, Current h1 f
| Current h1 f, Witnessed h0 ->
extends #a #p h1 h0
| Current h0 f0, Current h1 f1 ->
h0 == h1 /\
(sum_perm f0 f1).v <=. one
let history_compose #a #p (h0:history a p) (h1:history a p{history_composable h0 h1})
: history a p
= match h0, h1 with
| Witnessed h0, Witnessed h1 ->
Witnessed (p_op p h0 h1)
| Current h0 f, Witnessed h1
| Witnessed h1, Current h0 f ->
Current (p_op p h1 h0) f
| Current h0 f0, Current _ f1 ->
Current h0 (sum_perm f0 f1)
let unit_history #a #p : history a p = Witnessed []
let lem_is_unit #a #p (x:history a p)
: Lemma (history_composable x unit_history /\
history_compose x unit_history == x)
= match x with
| Witnessed h -> ()
| Current h _ ->
assert (forall (h:hist p). p_composable p h []);
assert (forall (h:hist p). p_op p h [] == h);
assert (forall (h:vhist p). extends #a #p h []);
assert (h =!= []);
assert (extends #a #p h [])
#push-options "--z3rlimit_factor 2"
let assoc_l #a #p (x y:history a p)
(z:history a p{history_composable y z /\
history_composable x (history_compose y z)})
: Lemma (history_composable x y /\
history_composable (history_compose x y) z /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
let assoc_r #a #p (x y:history a p)
(z:history a p{history_composable x y /\
history_composable (history_compose x y) z})
: Lemma (history_composable y z /\
history_composable x (history_compose y z) /\
history_compose (history_compose x y) z ==
history_compose x (history_compose y z))
= ()
#pop-options
let pcm_history #a #p : pcm (history a p) = {
p = {
composable = history_composable;
op = history_compose;
one = unit_history
};
comm = (fun _ _ -> ());
assoc = assoc_l;
assoc_r = assoc_r;
is_unit = lem_is_unit;
refine = (fun _ -> True);
}
let pcm_history_preorder #a #p : preorder (history a p) =
fun h0 h1 ->
match h0, h1 with
| Witnessed vh0, Witnessed vh1
| Current vh0 _, Witnessed vh1
| Witnessed vh0, Current vh1 _
| Current vh0 _, Current vh1 _ ->
vh1 `extends` vh0 | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.Preorder.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 8,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Pervasives.Lemma
(ensures
PulseCore.Preorder.induces_preorder PulseCore.Preorder.pcm_history
PulseCore.Preorder.pcm_history_preorder) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.Preorder.history",
"FStar.PCM.frame_preserving_upd",
"PulseCore.Preorder.pcm_history",
"Prims.unit",
"FStar.PCM.compatible",
"Prims.squash",
"PulseCore.Preorder.pcm_history_preorder",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"FStar.Pervasives.Native.Mktuple3",
"PulseCore.Preorder.hist",
"Prims._assert",
"FStar.PCM.composable",
"PulseCore.Preorder.vhist",
"PulseCore.FractionalPermission.perm",
"PulseCore.Preorder.Witnessed",
"Prims.eq2",
"PulseCore.Preorder.extends",
"Prims.l_and",
"FStar.PCM.op",
"FStar.IndefiniteDescription.indefinite_description_ghost",
"Prims.prop",
"FStar.PCM.__proj__Mkpcm__item__refine",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.PCM.pcm",
"Prims.l_True",
"PulseCore.Preorder.induces_preorder"
] | [] | false | false | true | false | false | let pcm_history_induces_preorder #a #p
: Lemma (induces_preorder (pcm_history #a #p) (pcm_history_preorder #a #p)) =
| let aux (x y: history a p) (f: frame_preserving_upd (pcm_history #a #p) x y) (v: history a p)
: Lemma (requires compatible (pcm_history #a #p) x v)
(ensures (pcm_history_preorder #a #p) v (f v))
[SMTPat ()] =
let pcm = pcm_history #a #p in
let v1 = f v in
match x, v, v1 with
| Witnessed _, Witnessed _, Witnessed _ -> assert (composable pcm x v)
| Current _ _, Witnessed _, Witnessed _ -> ()
| Witnessed _, Current _ _, Witnessed _ -> ()
| Witnessed _, Witnessed _, Current _ _ -> assert (composable pcm x v)
| Current _ _, Witnessed _, Current _ _ -> ()
| Witnessed _, Current _ _, Current _ _ -> ()
| Current hx _, Current hv _, Witnessed _
| Current hx _, Current hv _, Current _ _ ->
let frame =
FStar.IndefiniteDescription.indefinite_description_ghost (history a p)
(fun frame -> composable pcm x frame /\ op pcm frame x == v)
in
match frame with
| Current hf _ -> ()
| Witnessed hf ->
assert (extends hx hf);
assert (hx == hv);
assert (composable pcm x (Witnessed hv))
in
() | false |
Sec2.HIFC.fst | Sec2.HIFC.post | val post : a: Type -> Type | let post a = store -> a -> store -> Type0 | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 12,
"start_col": 0,
"start_line": 12
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.store"
] | [] | false | false | false | true | true | let post a =
| store -> a -> store -> Type0 | false |
|
Hacl.HPKE.Interface.AEAD.fst | Hacl.HPKE.Interface.AEAD.aead_encrypt_cp32 | val aead_encrypt_cp32 : aead_encrypt_st (S.Seal AEAD.CHACHA20_POLY1305) | val aead_encrypt_cp32 : aead_encrypt_st (S.Seal AEAD.CHACHA20_POLY1305) | let aead_encrypt_cp32 =
fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_32.encrypt cipher tag input len aad alen key nonce | {
"file_name": "code/hpke/Hacl.HPKE.Interface.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 25,
"start_col": 0,
"start_line": 21
} | module Hacl.HPKE.Interface.AEAD
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.Buffer
friend Spec.Agile.AEAD
/// These two functions will never be extracted, they are only an interface
/// boundary for the tactic performing instantiations.
/// In other files, it is exposed as an assume val, but for AEAD, we need an fsti
/// since we need to friend Spec.Agile.AEAD to perform the instantiations below,
/// and assume val are forbidden in interface files
let aead_encrypt #cs = admit()
let aead_decrypt #cs = admit()
#set-options "--z3rlimit 60 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Chacha20Poly1305_32.fst.checked",
"Hacl.Chacha20Poly1305_256.fst.checked",
"Hacl.Chacha20Poly1305_128.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.Interface.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.HPKE.Interface.AEAD.aead_encrypt_st (Spec.Agile.HPKE.Seal Spec.Agile.AEAD.CHACHA20_POLY1305) | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.l_and",
"Prims.b2t",
"Spec.Agile.HPKE.uu___is_Seal",
"Spec.Agile.HPKE.Seal",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"Spec.Agile.HPKE.is_valid_aead",
"Hacl.HPKE.Interface.AEAD.kv",
"Spec.Agile.HPKE.__proj__Seal__item__alg",
"Hacl.HPKE.Interface.AEAD.iv",
"Lib.IntTypes.size_t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Agile.AEAD.max_length",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.size",
"Hacl.Chacha20Poly1305_32.encrypt",
"Prims.unit",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let aead_encrypt_cp32 =
| fun _ key nonce alen aad len input output ->
let cipher = sub output 0ul len in
let tag = sub output len 16ul in
Hacl.Chacha20Poly1305_32.encrypt cipher tag input len aad alen key nonce | false |
Sec2.HIFC.fst | Sec2.HIFC.upd | val upd (s: store) (l: loc) (x: int) : store | val upd (s: store) (l: loc) (x: int) : store | let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 57,
"end_line": 6,
"start_col": 0,
"start_line": 6
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: Sec2.HIFC.store -> l: Sec2.HIFC.loc -> x: Prims.int -> Sec2.HIFC.store | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.store",
"Sec2.HIFC.loc",
"Prims.int",
"FStar.Map.upd"
] | [] | false | false | false | true | false | let upd (s: store) (l: loc) (x: int) : store =
| Map.upd s l x | false |
Sec2.HIFC.fst | Sec2.HIFC.label_inclusion | val label_inclusion : l0: Sec2.HIFC.label -> l1: Sec2.HIFC.label -> Prims.logical | let label_inclusion (l0 l1:label) = Set.subset l0 l1 | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 49,
"start_col": 0,
"start_line": 49
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | l0: Sec2.HIFC.label -> l1: Sec2.HIFC.label -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"FStar.Set.subset",
"Sec2.HIFC.loc",
"Prims.logical"
] | [] | false | false | false | true | true | let label_inclusion (l0 l1: label) =
| Set.subset l0 l1 | false |
|
Sec2.HIFC.fst | Sec2.HIFC.bot | val bot:label | val bot:label | let bot : label = Set.empty | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 50,
"start_col": 0,
"start_line": 50
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | Sec2.HIFC.label | Prims.Tot | [
"total"
] | [] | [
"FStar.Set.empty",
"Sec2.HIFC.loc"
] | [] | false | false | false | true | false | let bot:label =
| Set.empty | false |
Sec2.HIFC.fst | Sec2.HIFC.return_hst | val return_hst (a: _) (x: a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) | val return_hst (a: _) (x: a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) | let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 97,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> x: a -> Sec2.HIFC.hst a (fun _ -> Prims.l_True) (fun s0 r s1 -> s0 == s1 /\ r == x) | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.store",
"Prims.l_True",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Sec2.HIFC.hst"
] | [] | false | false | false | false | false | let return_hst a (x: a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
| fun s -> x, s | false |
Sec2.HIFC.fst | Sec2.HIFC.label | val label : Type0 | let label = Set.set loc | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 48,
"start_col": 0,
"start_line": 48
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Set.set",
"Sec2.HIFC.loc"
] | [] | false | false | false | true | true | let label =
| Set.set loc | false |
|
Sec2.HIFC.fst | Sec2.HIFC.is_empty | val is_empty : s: FStar.Set.set a -> Prims.logical | let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 53,
"start_col": 0,
"start_line": 53
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Set.set a -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.Set.set",
"Prims.l_Forall",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Prims.logical"
] | [] | false | false | false | false | true | let is_empty #a (s: Set.set a) =
| forall (x: a). ~(Set.mem x s) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.union | val union : l0: Sec2.HIFC.label -> l1: Sec2.HIFC.label -> FStar.Set.set Sec2.HIFC.loc | let union (l0 l1:label) = Set.union l0 l1 | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 52,
"start_col": 0,
"start_line": 52
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | l0: Sec2.HIFC.label -> l1: Sec2.HIFC.label -> FStar.Set.set Sec2.HIFC.loc | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"FStar.Set.union",
"Sec2.HIFC.loc",
"FStar.Set.set"
] | [] | false | false | false | true | false | let union (l0 l1: label) =
| Set.union l0 l1 | false |
|
Sec2.HIFC.fst | Sec2.HIFC.single | val single (l: loc) : label | val single (l: loc) : label | let single (l:loc) : label = Set.singleton l | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 51,
"start_col": 0,
"start_line": 51
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Sec2.HIFC.loc -> Sec2.HIFC.label | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.loc",
"FStar.Set.singleton",
"Sec2.HIFC.label"
] | [] | false | false | false | true | false | let single (l: loc) : label =
| Set.singleton l | false |
Sec2.HIFC.fst | Sec2.HIFC.modifies | val modifies : w: Sec2.HIFC.label -> s0: Sec2.HIFC.store -> s1: Sec2.HIFC.store -> Prims.logical | let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 111,
"end_line": 56,
"start_col": 0,
"start_line": 56
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | w: Sec2.HIFC.label -> s0: Sec2.HIFC.store -> s1: Sec2.HIFC.store -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"Sec2.HIFC.store",
"Prims.l_Forall",
"Sec2.HIFC.loc",
"Prims.l_imp",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Prims.eq2",
"Prims.int",
"Sec2.HIFC.sel",
"Prims.logical"
] | [] | false | false | false | true | true | let modifies (w: label) (s0 s1: store) =
| (forall l. {:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.subcomp_hst | val subcomp_hst (a: Type) (p q r s: _) (x: hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\ (forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True) | val subcomp_hst (a: Type) (p q r s: _) (x: hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\ (forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True) | let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 28,
"start_col": 0,
"start_line": 23
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
p: Sec2.HIFC.pre ->
q: Sec2.HIFC.post a ->
r: (_: Sec2.HIFC.store -> Prims.logical) ->
s: (_: Sec2.HIFC.store -> _: a -> _: Sec2.HIFC.store -> Prims.logical) ->
x: Sec2.HIFC.hst a p q
-> Prims.Pure (Sec2.HIFC.hst a r s) | Prims.Pure | [] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.store",
"Prims.logical",
"Sec2.HIFC.hst",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_True"
] | [] | false | false | false | false | false | let subcomp_hst (a: Type) p q r s (x: hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\ (forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True) =
| x | false |
Sec2.HIFC.fst | Sec2.HIFC.bind_hst | val bind_hst (a b: Type) (p q r s: _) (x: hst a p q) (y: (x: a -> hst b (r x) (s x)))
: hst b
(fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2)) | val bind_hst (a b: Type) (p q r s: _) (x: hst a p q) (y: (x: a -> hst b (r x) (s x)))
: hst b
(fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2)) | let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1 | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 22,
"start_col": 0,
"start_line": 16
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
b: Type ->
p: Sec2.HIFC.pre ->
q: Sec2.HIFC.post a ->
r: (_: a -> Sec2.HIFC.pre) ->
s: (_: a -> Sec2.HIFC.post b) ->
x: Sec2.HIFC.hst a p q ->
y: (x: a -> Sec2.HIFC.hst b (r x) (s x))
-> Sec2.HIFC.hst b
(fun s0 -> p s0 /\ (forall (x: a) (s1: Sec2.HIFC.store). q s0 x s1 ==> r x s1))
(fun s0 r s2 -> exists (x: a) (s1: Sec2.HIFC.store). q s0 x s1 /\ s x s1 r s2) | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.store",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.Pervasives.Native.tuple2",
"Prims.l_Exists",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | false | false | let bind_hst (a: Type) (b: Type) p q r s (x: hst a p q) (y: (x: a -> hst b (r x) (s x)))
: hst b
(fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2)) =
| fun s0 ->
let v, s1 = x s0 in
y v s1 | false |
Sec2.HIFC.fst | Sec2.HIFC.writes | val writes : f: Sec2.HIFC.hst a p q -> writes: Sec2.HIFC.label -> Prims.logical | let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0' | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 73,
"end_line": 58,
"start_col": 0,
"start_line": 57
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> writes: Sec2.HIFC.label -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.label",
"Prims.l_Forall",
"Sec2.HIFC.store",
"Sec2.HIFC.modifies",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Prims.logical"
] | [] | false | false | false | false | true | let writes #a #p #q (f: hst a p q) (writes: label) =
| forall (s0: store{p s0}).
let x1, s0' = f s0 in
modifies writes s0 s0' | false |
|
Sec2.HIFC.fst | Sec2.HIFC.reads | val reads : f: Sec2.HIFC.hst a p q -> reads: Sec2.HIFC.label -> Prims.logical | let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0' | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 95,
"end_line": 68,
"start_col": 0,
"start_line": 67
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> reads: Sec2.HIFC.label -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.label",
"Prims.l_Forall",
"Sec2.HIFC.store",
"Prims.l_imp",
"Sec2.HIFC.agree_on",
"Sec2.HIFC.related_runs",
"Prims.logical"
] | [] | false | false | false | false | true | let reads #a #p #q (f: hst a p q) (reads: label) =
| forall (s0: store{p s0}) (s0': store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0' | false |
|
Sec2.HIFC.fst | Sec2.HIFC.agree_on | val agree_on : reads: Sec2.HIFC.label -> s0: Sec2.HIFC.store -> s1: Sec2.HIFC.store -> Prims.logical | let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 94,
"end_line": 61,
"start_col": 0,
"start_line": 61
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | reads: Sec2.HIFC.label -> s0: Sec2.HIFC.store -> s1: Sec2.HIFC.store -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"Sec2.HIFC.store",
"Prims.l_Forall",
"Sec2.HIFC.loc",
"Prims.l_imp",
"Prims.b2t",
"FStar.Set.mem",
"Prims.eq2",
"Prims.int",
"Sec2.HIFC.sel",
"Prims.logical"
] | [] | false | false | false | true | true | let agree_on (reads: label) (s0 s1: store) =
| forall l. Set.mem l reads ==> sel s0 l == sel s1 l | false |
|
Sec2.HIFC.fst | Sec2.HIFC.has_flow_1 | val has_flow_1 : from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> f: Sec2.HIFC.flow -> Prims.logical | let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 82,
"end_line": 73,
"start_col": 0,
"start_line": 73
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> f: Sec2.HIFC.flow -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.loc",
"Sec2.HIFC.flow",
"Prims.l_and",
"Prims.b2t",
"FStar.Set.mem",
"FStar.Pervasives.Native.fst",
"Sec2.HIFC.label",
"FStar.Pervasives.Native.snd",
"Prims.logical"
] | [] | false | false | false | true | true | let has_flow_1 (from to: loc) (f: flow) =
| from `Set.mem` (fst f) /\ to `Set.mem` (snd f) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.flow | val flow : Type0 | let flow = label & label | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 71,
"start_col": 0,
"start_line": 71
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Sec2.HIFC.label"
] | [] | false | false | false | true | true | let flow =
| label & label | false |
|
Sec2.HIFC.fst | Sec2.HIFC.related_runs | val related_runs : f: Sec2.HIFC.hst a p q -> s0: Sec2.HIFC.store{p s0} -> s0': Sec2.HIFC.store{p s0'} -> Prims.logical | let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l)))) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 101,
"end_line": 66,
"start_col": 0,
"start_line": 62
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> s0: Sec2.HIFC.store{p s0} -> s0': Sec2.HIFC.store{p s0'} -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.store",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"Sec2.HIFC.loc",
"Prims.l_or",
"Prims.int",
"Sec2.HIFC.sel",
"Prims.logical",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | false | true | let related_runs #a #p #q (f: hst a p q) (s0: store{p s0}) (s0': store{p s0'}) =
| (let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l: loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l)))) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.has_flow | val has_flow : from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> fs: Sec2.HIFC.flows -> Prims.logical | let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 99,
"end_line": 74,
"start_col": 0,
"start_line": 74
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> fs: Sec2.HIFC.flows -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.loc",
"Sec2.HIFC.flows",
"Prims.l_Exists",
"Sec2.HIFC.flow",
"Prims.l_and",
"FStar.List.Tot.Base.memP",
"Sec2.HIFC.has_flow_1",
"Prims.logical"
] | [] | false | false | false | true | true | let has_flow (from to: loc) (fs: flows) =
| (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.flows | val flows : Type0 | let flows = list flow | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 72,
"start_col": 0,
"start_line": 72
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Sec2.HIFC.flow"
] | [] | false | false | false | true | true | let flows =
| list flow | false |
|
Sec2.HIFC.fst | Sec2.HIFC.no_leakage | val no_leakage : f: Sec2.HIFC.hst a p q -> from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> Prims.logical | let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 88,
"end_line": 79,
"start_col": 0,
"start_line": 79
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.loc",
"Prims.l_Forall",
"Prims.int",
"Sec2.HIFC.no_leakage_k",
"Prims.logical"
] | [] | false | false | false | false | true | let no_leakage #a #p #q (f: hst a p q) (from: loc) (to: loc) =
| forall k. no_leakage_k f from to k | false |
|
Sec2.HIFC.fst | Sec2.HIFC.respects | val respects : f: Sec2.HIFC.hst a p q -> fs: Sec2.HIFC.flows -> Prims.logical | let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 115,
"end_line": 81,
"start_col": 0,
"start_line": 80
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> fs: Sec2.HIFC.flows -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.flows",
"Prims.l_Forall",
"Sec2.HIFC.loc",
"Prims.l_imp",
"Prims.l_and",
"Prims.l_not",
"Sec2.HIFC.has_flow",
"Prims.b2t",
"Prims.op_disEquality",
"Sec2.HIFC.no_leakage",
"Prims.logical"
] | [] | false | false | false | false | true | let respects #a #p #q (f: hst a p q) (fs: flows) =
| (forall from to. {:pattern (no_leakage f from to)}
~(has_flow from to fs) /\ from <> to ==> no_leakage f from to) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.hifc | val hifc : a: Type ->
r: Sec2.HIFC.label ->
w: Sec2.HIFC.label ->
fs: Sec2.HIFC.flows ->
p: Sec2.HIFC.pre ->
q: Sec2.HIFC.post a
-> Type | let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
} | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 91,
"start_col": 0,
"start_line": 86
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects` | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
r: Sec2.HIFC.label ->
w: Sec2.HIFC.label ->
fs: Sec2.HIFC.flows ->
p: Sec2.HIFC.pre ->
q: Sec2.HIFC.post a
-> Type | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"Sec2.HIFC.flows",
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Prims.l_and",
"Sec2.HIFC.reads",
"Sec2.HIFC.writes",
"Sec2.HIFC.respects"
] | [] | false | false | false | true | true | let hifc a (r: label) (w: label) (fs: flows) (p: pre) (q: post a) =
| f: hst a p q {reads f r /\ writes f w /\ respects f fs} | false |
|
Hacl.FFDHE.fst | Hacl.FFDHE.ffdhe_compute_exp | val ffdhe_compute_exp (a: S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) | val ffdhe_compute_exp (a: S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) | let ffdhe_compute_exp (a:S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_compute_exp a (DH.ffdhe_len a) (ke a) | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 32,
"start_col": 0,
"start_line": 31
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private
[@CInline]
let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a)
private
[@CInline]
let ffdhe_check_pk (a:S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a)
private | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg
-> Hacl.Impl.FFDHE.ffdhe_compute_exp_st Hacl.FFDHE.t_limbs
a
(Hacl.Impl.FFDHE.ffdhe_len a)
(Hacl.FFDHE.ke a) | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Impl.FFDHE.ffdhe_compute_exp",
"Hacl.FFDHE.t_limbs",
"Hacl.Impl.FFDHE.ffdhe_len",
"Hacl.FFDHE.ke",
"Hacl.Impl.FFDHE.ffdhe_compute_exp_st"
] | [] | false | false | false | false | false | let ffdhe_compute_exp (a: S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) =
| DH.ffdhe_compute_exp a (DH.ffdhe_len a) (ke a) | false |
Hacl.FFDHE.fst | Hacl.FFDHE.ffdhe_check_pk | val ffdhe_check_pk (a: S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) | val ffdhe_check_pk (a: S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) | let ffdhe_check_pk (a:S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a) | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 27,
"start_col": 0,
"start_line": 26
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private
[@CInline]
let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a)
private | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg
-> Hacl.Impl.FFDHE.ffdhe_check_pk_st Hacl.FFDHE.t_limbs a (Hacl.Impl.FFDHE.ffdhe_len a) | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Impl.FFDHE.ffdhe_check_pk",
"Hacl.FFDHE.t_limbs",
"Hacl.Impl.FFDHE.ffdhe_len",
"Hacl.Impl.FFDHE.ffdhe_check_pk_st"
] | [] | false | false | false | false | false | let ffdhe_check_pk (a: S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
| DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a) | false |
Sec2.HIFC.fst | Sec2.HIFC.does_not_read_loc | val does_not_read_loc : f: Sec2.HIFC.hst a p q -> reads: Sec2.HIFC.label -> l: Sec2.HIFC.loc -> s0: Sec2.HIFC.store{p s0}
-> Prims.logical | let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"end_line": 128,
"start_col": 0,
"start_line": 127
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> reads: Sec2.HIFC.label -> l: Sec2.HIFC.loc -> s0: Sec2.HIFC.store{p s0}
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.label",
"Sec2.HIFC.loc",
"Sec2.HIFC.store",
"Prims.l_Forall",
"Prims.int",
"Sec2.HIFC.does_not_read_loc_v",
"Prims.logical"
] | [] | false | false | false | false | true | let does_not_read_loc #a #p #q (f: hst a p q) (reads: label) (l: loc) (s0: store{p s0}) =
| forall v. does_not_read_loc_v f reads l s0 v | false |
|
Hacl.FFDHE.fst | Hacl.FFDHE.new_ffdhe_precomp_p | val new_ffdhe_precomp_p: a:S.ffdhe_alg ->
DH.new_ffdhe_precomp_p_st t_limbs a (ffdhe_len a) (ke a) | val new_ffdhe_precomp_p: a:S.ffdhe_alg ->
DH.new_ffdhe_precomp_p_st t_limbs a (ffdhe_len a) (ke a) | let new_ffdhe_precomp_p a =
DH.new_ffdhe_precomp_p a (DH.ffdhe_len a) (ke a) (ffdhe_precomp_p a) | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 41,
"start_col": 0,
"start_line": 40
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private
[@CInline]
let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a)
private
[@CInline]
let ffdhe_check_pk (a:S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a)
private
[@CInline]
let ffdhe_compute_exp (a:S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_compute_exp a (DH.ffdhe_len a) (ke a)
let ffdhe_len (a:S.ffdhe_alg) : DH.size_pos = DH.ffdhe_len a
val new_ffdhe_precomp_p: a:S.ffdhe_alg -> | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg
-> Hacl.Impl.FFDHE.new_ffdhe_precomp_p_st Hacl.FFDHE.t_limbs
a
(Hacl.FFDHE.ffdhe_len a)
(Hacl.FFDHE.ke a) | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Impl.FFDHE.new_ffdhe_precomp_p",
"Hacl.FFDHE.t_limbs",
"Hacl.Impl.FFDHE.ffdhe_len",
"Hacl.FFDHE.ke",
"Hacl.FFDHE.ffdhe_precomp_p",
"Hacl.Impl.FFDHE.new_ffdhe_precomp_p_st",
"Hacl.FFDHE.ffdhe_len"
] | [] | false | false | false | false | false | let new_ffdhe_precomp_p a =
| DH.new_ffdhe_precomp_p a (DH.ffdhe_len a) (ke a) (ffdhe_precomp_p a) | false |
Hacl.FFDHE.fst | Hacl.FFDHE.ffdhe_precomp_p | val ffdhe_precomp_p (a: S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) | val ffdhe_precomp_p (a: S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) | let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a) | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 22,
"start_col": 0,
"start_line": 21
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg
-> Hacl.Impl.FFDHE.ffdhe_precomp_p_st Hacl.FFDHE.t_limbs
a
(Hacl.Impl.FFDHE.ffdhe_len a)
(Hacl.FFDHE.ke a) | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Impl.FFDHE.ffdhe_precomp_p",
"Hacl.FFDHE.t_limbs",
"Hacl.Impl.FFDHE.ffdhe_len",
"Hacl.FFDHE.ke",
"Hacl.Impl.FFDHE.ffdhe_precomp_p_st"
] | [] | false | false | false | false | false | let ffdhe_precomp_p (a: S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
| DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a) | false |
Sec2.HIFC.fst | Sec2.HIFC.return | val return (a: Type) (x: a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) | val return (a: Type) (x: a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) | let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 96,
"start_col": 0,
"start_line": 94
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> x: a
-> Sec2.HIFC.hifc a
Sec2.HIFC.bot
Sec2.HIFC.bot
[]
(fun _ -> Prims.l_True)
(fun s0 r s1 -> s0 == s1 /\ r == x) | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.hst",
"Sec2.HIFC.store",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Sec2.HIFC.hifc",
"Sec2.HIFC.bot",
"Prims.Nil",
"Sec2.HIFC.flow"
] | [] | false | false | false | false | false | let return (a: Type) (x: a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
| let f:hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x, s in
f | false |
Sec2.HIFC.fst | Sec2.HIFC.add_source | val add_source (r: label) (fs: flows) : flows | val add_source (r: label) (fs: flows) : flows | let add_source (r:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> union r r0, w0) fs | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 94,
"end_line": 162,
"start_col": 0,
"start_line": 162
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l)))
let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v
let reads_ok_preserves_equal_locs #a #p #q (f:hst a p q) (rds:label) (s0:store{p s0}) (s0':store{p s0'})
: Lemma (requires agree_on rds s0 s0' /\ reads f rds)
(ensures (let x1, s1 = f s0 in
let x1', s1' = f s0' in
agree_on rds s1 s1'))
= ()
let weaken_reads_ok #a #p #q (f:hst a p q) (rds rds1:label)
: Lemma (requires reads f rds /\
label_inclusion rds rds1)
(ensures reads f rds1)
= let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat(agree_on rds1 s0 s0')]
= ()
in
()
let reads_ok_does_not_read_loc #a #p #q (f:hst a p q) (rds:label) (l:loc{~(Set.mem l rds)}) (s0:store{p s0})
: Lemma
(requires reads f rds)
(ensures does_not_read_loc f rds l s0)
= let aux (v:int)
: Lemma (requires p (upd s0 l v))
(ensures does_not_read_loc_v f rds l s0 v)
[SMTPat ((upd s0 l v))]
= assert (agree_on rds s0 (upd s0 l v));
()
in
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: Sec2.HIFC.label -> fs: Sec2.HIFC.flows -> Sec2.HIFC.flows | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"Sec2.HIFC.flows",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.tuple2",
"FStar.Set.set",
"Sec2.HIFC.loc",
"FStar.Pervasives.Native.Mktuple2",
"Sec2.HIFC.union"
] | [] | false | false | false | true | false | let add_source (r: label) (fs: flows) : flows =
| List.Tot.map (fun (r0, w0) -> union r r0, w0) fs | false |
Sec2.HIFC.fst | Sec2.HIFC.no_leakage_k | val no_leakage_k : f: Sec2.HIFC.hst a p q -> from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> k: Prims.int -> Prims.logical | let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 78,
"start_col": 0,
"start_line": 75
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> from: Sec2.HIFC.loc -> to: Sec2.HIFC.loc -> k: Prims.int -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.loc",
"Prims.int",
"Prims.l_Forall",
"Sec2.HIFC.store",
"Prims.l_imp",
"Sec2.HIFC.upd",
"Prims.eq2",
"Sec2.HIFC.sel",
"FStar.Pervasives.Native.snd",
"Prims.logical"
] | [] | false | false | false | false | true | let no_leakage_k #a #p #q (f: hst a p q) (from: loc) (to: loc) (k: int) =
| forall (s0: store{p s0}). {:pattern (upd s0 from k)}
p (upd s0 from k) ==> sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.add_sink | val add_sink (w: label) (fs: flows) : flows | val add_sink (w: label) (fs: flows) : flows | let add_sink (w:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> r0, union w w0) fs | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 92,
"end_line": 163,
"start_col": 0,
"start_line": 163
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l)))
let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v
let reads_ok_preserves_equal_locs #a #p #q (f:hst a p q) (rds:label) (s0:store{p s0}) (s0':store{p s0'})
: Lemma (requires agree_on rds s0 s0' /\ reads f rds)
(ensures (let x1, s1 = f s0 in
let x1', s1' = f s0' in
agree_on rds s1 s1'))
= ()
let weaken_reads_ok #a #p #q (f:hst a p q) (rds rds1:label)
: Lemma (requires reads f rds /\
label_inclusion rds rds1)
(ensures reads f rds1)
= let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat(agree_on rds1 s0 s0')]
= ()
in
()
let reads_ok_does_not_read_loc #a #p #q (f:hst a p q) (rds:label) (l:loc{~(Set.mem l rds)}) (s0:store{p s0})
: Lemma
(requires reads f rds)
(ensures does_not_read_loc f rds l s0)
= let aux (v:int)
: Lemma (requires p (upd s0 l v))
(ensures does_not_read_loc_v f rds l s0 v)
[SMTPat ((upd s0 l v))]
= assert (agree_on rds s0 (upd s0 l v));
()
in
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | w: Sec2.HIFC.label -> fs: Sec2.HIFC.flows -> Sec2.HIFC.flows | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"Sec2.HIFC.flows",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.tuple2",
"FStar.Set.set",
"Sec2.HIFC.loc",
"FStar.Pervasives.Native.Mktuple2",
"Sec2.HIFC.union"
] | [] | false | false | false | true | false | let add_sink (w: label) (fs: flows) : flows =
| List.Tot.map (fun (r0, w0) -> r0, union w w0) fs | false |
Sec2.HIFC.fst | Sec2.HIFC.flows_equiv | val flows_equiv : fs0: Sec2.HIFC.flows -> fs1: Sec2.HIFC.flows -> Prims.logical | let flows_equiv (fs0 fs1:flows) = fs0 `flows_included_in` fs1 /\ fs1 `flows_included_in` fs0 | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 92,
"end_line": 169,
"start_col": 0,
"start_line": 169
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l)))
let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v
let reads_ok_preserves_equal_locs #a #p #q (f:hst a p q) (rds:label) (s0:store{p s0}) (s0':store{p s0'})
: Lemma (requires agree_on rds s0 s0' /\ reads f rds)
(ensures (let x1, s1 = f s0 in
let x1', s1' = f s0' in
agree_on rds s1 s1'))
= ()
let weaken_reads_ok #a #p #q (f:hst a p q) (rds rds1:label)
: Lemma (requires reads f rds /\
label_inclusion rds rds1)
(ensures reads f rds1)
= let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat(agree_on rds1 s0 s0')]
= ()
in
()
let reads_ok_does_not_read_loc #a #p #q (f:hst a p q) (rds:label) (l:loc{~(Set.mem l rds)}) (s0:store{p s0})
: Lemma
(requires reads f rds)
(ensures does_not_read_loc f rds l s0)
= let aux (v:int)
: Lemma (requires p (upd s0 l v))
(ensures does_not_read_loc_v f rds l s0 v)
[SMTPat ((upd s0 l v))]
= assert (agree_on rds s0 (upd s0 l v));
()
in
()
let add_source (r:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> union r r0, w0) fs
let add_sink (w:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> r0, union w w0) fs
let flows_included_in (fs0 fs1:flows) =
forall f0. f0 `List.Tot.memP` fs0 ==>
(forall from to. has_flow_1 from to f0 /\ from <> to ==> (exists f1. f1 `List.Tot.memP` fs1 /\ has_flow_1 from to f1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | fs0: Sec2.HIFC.flows -> fs1: Sec2.HIFC.flows -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.flows",
"Prims.l_and",
"Sec2.HIFC.flows_included_in",
"Prims.logical"
] | [] | false | false | false | true | true | let flows_equiv (fs0 fs1: flows) =
| fs0 `flows_included_in` fs1 /\ fs1 `flows_included_in` fs0 | false |
|
Sec2.HIFC.fst | Sec2.HIFC.flows_included_in | val flows_included_in : fs0: Sec2.HIFC.flows -> fs1: Sec2.HIFC.flows -> Prims.logical | let flows_included_in (fs0 fs1:flows) =
forall f0. f0 `List.Tot.memP` fs0 ==>
(forall from to. has_flow_1 from to f0 /\ from <> to ==> (exists f1. f1 `List.Tot.memP` fs1 /\ has_flow_1 from to f1)) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 126,
"end_line": 167,
"start_col": 0,
"start_line": 165
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l)))
let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v
let reads_ok_preserves_equal_locs #a #p #q (f:hst a p q) (rds:label) (s0:store{p s0}) (s0':store{p s0'})
: Lemma (requires agree_on rds s0 s0' /\ reads f rds)
(ensures (let x1, s1 = f s0 in
let x1', s1' = f s0' in
agree_on rds s1 s1'))
= ()
let weaken_reads_ok #a #p #q (f:hst a p q) (rds rds1:label)
: Lemma (requires reads f rds /\
label_inclusion rds rds1)
(ensures reads f rds1)
= let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat(agree_on rds1 s0 s0')]
= ()
in
()
let reads_ok_does_not_read_loc #a #p #q (f:hst a p q) (rds:label) (l:loc{~(Set.mem l rds)}) (s0:store{p s0})
: Lemma
(requires reads f rds)
(ensures does_not_read_loc f rds l s0)
= let aux (v:int)
: Lemma (requires p (upd s0 l v))
(ensures does_not_read_loc_v f rds l s0 v)
[SMTPat ((upd s0 l v))]
= assert (agree_on rds s0 (upd s0 l v));
()
in
()
let add_source (r:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> union r r0, w0) fs
let add_sink (w:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> r0, union w w0) fs | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | fs0: Sec2.HIFC.flows -> fs1: Sec2.HIFC.flows -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.flows",
"Prims.l_Forall",
"Sec2.HIFC.flow",
"Prims.l_imp",
"FStar.List.Tot.Base.memP",
"Sec2.HIFC.loc",
"Prims.l_and",
"Sec2.HIFC.has_flow_1",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.l_Exists",
"Prims.logical"
] | [] | false | false | false | true | true | let flows_included_in (fs0 fs1: flows) =
| forall f0.
f0 `List.Tot.memP` fs0 ==>
(forall from to.
has_flow_1 from to f0 /\ from <> to ==>
(exists f1. f1 `List.Tot.memP` fs1 /\ has_flow_1 from to f1)) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.iwrite | val iwrite (l: loc) (x: int)
: hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) | val iwrite (l: loc) (x: int)
: hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) | let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 106,
"start_col": 0,
"start_line": 104
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Sec2.HIFC.loc -> x: Prims.int
-> Sec2.HIFC.hifc Prims.unit
Sec2.HIFC.bot
(Sec2.HIFC.single l)
[]
(fun _ -> Prims.l_True)
(fun s0 _ s1 -> s1 == Sec2.HIFC.upd s0 l x) | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.loc",
"Prims.int",
"Sec2.HIFC.hst",
"Prims.unit",
"Sec2.HIFC.store",
"Prims.l_True",
"Prims.eq2",
"Sec2.HIFC.upd",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Sec2.HIFC.hifc",
"Sec2.HIFC.bot",
"Sec2.HIFC.single",
"Prims.Nil",
"Sec2.HIFC.flow"
] | [] | false | false | false | false | false | let iwrite (l: loc) (x: int)
: hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
| let f:hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f | false |
Sec2.HIFC.fst | Sec2.HIFC.does_not_read_loc_v | val does_not_read_loc_v : f: Sec2.HIFC.hst a p q ->
reads: Sec2.HIFC.label ->
l: Sec2.HIFC.loc ->
s0: Sec2.HIFC.store{p s0} ->
v: Prims.int
-> Prims.logical | let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l))) | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 125,
"start_col": 0,
"start_line": 110
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: Sec2.HIFC.hst a p q ->
reads: Sec2.HIFC.label ->
l: Sec2.HIFC.loc ->
s0: Sec2.HIFC.store{p s0} ->
v: Prims.int
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.label",
"Sec2.HIFC.loc",
"Sec2.HIFC.store",
"Prims.int",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"Prims.b2t",
"Prims.op_disEquality",
"Sec2.HIFC.sel",
"Prims.l_or",
"Prims.logical",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Sec2.HIFC.upd"
] | [] | false | false | false | false | true | let does_not_read_loc_v #a #p #q (f: hst a p q) (reads: label) (l: loc) (s0: store{p s0}) v =
| let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ (forall l'. l' <> l ==> sel s1 l' == sel s1' l') /\
(sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))) | false |
|
Hacl.FFDHE.fst | Hacl.FFDHE.ffdhe_secret_to_public | val ffdhe_secret_to_public: a:S.ffdhe_alg ->
DH.ffdhe_secret_to_public_st t_limbs a (DH.ffdhe_len a) (ke a) | val ffdhe_secret_to_public: a:S.ffdhe_alg ->
DH.ffdhe_secret_to_public_st t_limbs a (DH.ffdhe_len a) (ke a) | let ffdhe_secret_to_public a sk pk =
let len = DH.ffdhe_len a in
DH.ffdhe_secret_to_public a len (ke a) (ffdhe_secret_to_public_precomp a) (ffdhe_precomp_p a) sk pk | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 101,
"end_line": 55,
"start_col": 0,
"start_line": 53
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private
[@CInline]
let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a)
private
[@CInline]
let ffdhe_check_pk (a:S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a)
private
[@CInline]
let ffdhe_compute_exp (a:S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_compute_exp a (DH.ffdhe_len a) (ke a)
let ffdhe_len (a:S.ffdhe_alg) : DH.size_pos = DH.ffdhe_len a
val new_ffdhe_precomp_p: a:S.ffdhe_alg ->
DH.new_ffdhe_precomp_p_st t_limbs a (ffdhe_len a) (ke a)
let new_ffdhe_precomp_p a =
DH.new_ffdhe_precomp_p a (DH.ffdhe_len a) (ke a) (ffdhe_precomp_p a)
val ffdhe_secret_to_public_precomp: a:S.ffdhe_alg ->
DH.ffdhe_secret_to_public_precomp_st t_limbs a (DH.ffdhe_len a) (ke a)
let ffdhe_secret_to_public_precomp a p_r2_n sk pk =
let len = DH.ffdhe_len a in
DH.ffdhe_secret_to_public_precomp a len (ke a) (ffdhe_compute_exp a) p_r2_n sk pk
val ffdhe_secret_to_public: a:S.ffdhe_alg -> | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg
-> Hacl.Impl.FFDHE.ffdhe_secret_to_public_st Hacl.FFDHE.t_limbs
a
(Hacl.Impl.FFDHE.ffdhe_len a)
(Hacl.FFDHE.ke a) | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.FFDHE.ffdhe_len",
"Hacl.Impl.FFDHE.ffdhe_secret_to_public",
"Hacl.FFDHE.t_limbs",
"Hacl.FFDHE.ke",
"Hacl.FFDHE.ffdhe_secret_to_public_precomp",
"Hacl.FFDHE.ffdhe_precomp_p",
"Prims.unit",
"Hacl.Impl.FFDHE.size_pos",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.FFDHE.ffdhe_len"
] | [] | false | false | false | false | false | let ffdhe_secret_to_public a sk pk =
| let len = DH.ffdhe_len a in
DH.ffdhe_secret_to_public a len (ke a) (ffdhe_secret_to_public_precomp a) (ffdhe_precomp_p a) sk pk | false |
Sec2.HIFC.fst | Sec2.HIFC.weaken_reads_ok | val weaken_reads_ok (#a #p #q: _) (f: hst a p q) (rds rds1: label)
: Lemma (requires reads f rds /\ label_inclusion rds rds1) (ensures reads f rds1) | val weaken_reads_ok (#a #p #q: _) (f: hst a p q) (rds rds1: label)
: Lemma (requires reads f rds /\ label_inclusion rds rds1) (ensures reads f rds1) | let weaken_reads_ok #a #p #q (f:hst a p q) (rds rds1:label)
: Lemma (requires reads f rds /\
label_inclusion rds rds1)
(ensures reads f rds1)
= let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat(agree_on rds1 s0 s0')]
= ()
in
() | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 6,
"end_line": 147,
"start_col": 0,
"start_line": 137
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l)))
let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v
let reads_ok_preserves_equal_locs #a #p #q (f:hst a p q) (rds:label) (s0:store{p s0}) (s0':store{p s0'})
: Lemma (requires agree_on rds s0 s0' /\ reads f rds)
(ensures (let x1, s1 = f s0 in
let x1', s1' = f s0' in
agree_on rds s1 s1'))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Sec2.HIFC.hst a p q -> rds: Sec2.HIFC.label -> rds1: Sec2.HIFC.label
-> FStar.Pervasives.Lemma (requires Sec2.HIFC.reads f rds /\ Sec2.HIFC.label_inclusion rds rds1)
(ensures Sec2.HIFC.reads f rds1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.label",
"Sec2.HIFC.store",
"Prims.unit",
"Prims.l_and",
"Sec2.HIFC.agree_on",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil",
"Sec2.HIFC.reads",
"Sec2.HIFC.label_inclusion"
] | [] | false | false | true | false | false | let weaken_reads_ok #a #p #q (f: hst a p q) (rds: label) (rds1: label)
: Lemma (requires reads f rds /\ label_inclusion rds rds1) (ensures reads f rds1) =
| let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat (agree_on rds1 s0 s0')] =
()
in
() | false |
Hacl.FFDHE.fst | Hacl.FFDHE.ke | val ke : a: Spec.FFDHE.ffdhe_alg -> Hacl.Bignum.Exponentiation.exp Hacl.FFDHE.t_limbs | let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs))) | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 17,
"start_col": 0,
"start_line": 16
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64 | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg -> Hacl.Bignum.Exponentiation.exp Hacl.FFDHE.t_limbs | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Bignum.Exponentiation.mk_runtime_exp",
"Hacl.FFDHE.t_limbs",
"Hacl.Bignum.Definitions.blocks",
"Hacl.Impl.FFDHE.ffdhe_len",
"Lib.IntTypes.size",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Exponentiation.exp"
] | [] | false | false | false | true | false | let ke (a: S.ffdhe_alg) =
| BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs))) | false |
|
Sec2.HIFC.fst | Sec2.HIFC.iread | val iread (l: loc)
: hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) | val iread (l: loc)
: hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) | let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 101,
"start_col": 0,
"start_line": 99
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Sec2.HIFC.loc
-> Sec2.HIFC.hifc Prims.int
(Sec2.HIFC.single l)
Sec2.HIFC.bot
[]
(fun _ -> Prims.l_True)
(fun s0 x s1 -> s0 == s1 /\ x == Sec2.HIFC.sel s0 l) | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.loc",
"Sec2.HIFC.hst",
"Prims.int",
"Sec2.HIFC.store",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Sec2.HIFC.sel",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Sec2.HIFC.hifc",
"Sec2.HIFC.single",
"Sec2.HIFC.bot",
"Prims.Nil",
"Sec2.HIFC.flow"
] | [] | false | false | false | false | false | let iread (l: loc)
: hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
| let f:hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f | false |
ContextPollution.fst | ContextPollution.warmup | val warmup : x: Prims.bool{x == true} -> Prims.unit | let warmup (x:bool { x == true }) = assert x | {
"file_name": "share/steel/tests/ContextPollution.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 44,
"end_line": 3,
"start_col": 0,
"start_line": 3
} | module ContextPollution | {
"checked_file": "/",
"dependencies": [
"Steel.Array.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "ContextPollution.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 | x: Prims.bool{x == true} -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.eq2",
"Prims._assert",
"Prims.b2t",
"Prims.unit"
] | [] | false | false | false | false | false | let warmup (x: bool{x == true}) =
| assert x | false |
|
Sec2.HIFC.fst | Sec2.HIFC.bind_ifc' | val bind_ifc'
(#a #b: Type)
(#w0 #r0 #w1 #r1: label)
(#fs0 #fs1: flows)
(#p #q #r #s: _)
(x: hifc a r0 w0 fs0 p q)
(y: (x: a -> hifc b r1 w1 fs1 (r x) (s x)))
: hst b
(fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2)) | val bind_ifc'
(#a #b: Type)
(#w0 #r0 #w1 #r1: label)
(#fs0 #fs1: flows)
(#p #q #r #s: _)
(x: hifc a r0 w0 fs0 p q)
(y: (x: a -> hifc b r1 w1 fs1 (r x) (s x)))
: hst b
(fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2)) | let bind_ifc' (#a #b:Type)
(#w0 #r0 #w1 #r1:label)
(#fs0 #fs1:flows)
#p #q #r #s
(x:hifc a r0 w0 fs0 p q)
(y: (x:a -> hifc b r1 w1 fs1 (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= bind_hst _ _ _ _ _ _ x y | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 199,
"start_col": 0,
"start_line": 191
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l)))
let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v
let reads_ok_preserves_equal_locs #a #p #q (f:hst a p q) (rds:label) (s0:store{p s0}) (s0':store{p s0'})
: Lemma (requires agree_on rds s0 s0' /\ reads f rds)
(ensures (let x1, s1 = f s0 in
let x1', s1' = f s0' in
agree_on rds s1 s1'))
= ()
let weaken_reads_ok #a #p #q (f:hst a p q) (rds rds1:label)
: Lemma (requires reads f rds /\
label_inclusion rds rds1)
(ensures reads f rds1)
= let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat(agree_on rds1 s0 s0')]
= ()
in
()
let reads_ok_does_not_read_loc #a #p #q (f:hst a p q) (rds:label) (l:loc{~(Set.mem l rds)}) (s0:store{p s0})
: Lemma
(requires reads f rds)
(ensures does_not_read_loc f rds l s0)
= let aux (v:int)
: Lemma (requires p (upd s0 l v))
(ensures does_not_read_loc_v f rds l s0 v)
[SMTPat ((upd s0 l v))]
= assert (agree_on rds s0 (upd s0 l v));
()
in
()
let add_source (r:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> union r r0, w0) fs
let add_sink (w:label) (fs:flows) : flows = List.Tot.map (fun (r0, w0) -> r0, union w w0) fs
let flows_included_in (fs0 fs1:flows) =
forall f0. f0 `List.Tot.memP` fs0 ==>
(forall from to. has_flow_1 from to f0 /\ from <> to ==> (exists f1. f1 `List.Tot.memP` fs1 /\ has_flow_1 from to f1))
let flows_equiv (fs0 fs1:flows) = fs0 `flows_included_in` fs1 /\ fs1 `flows_included_in` fs0
let flows_equiv_refl fs
: Lemma (fs `flows_equiv` fs)
= ()
let flows_equiv_trans fs0 fs1 fs2
: Lemma (fs0 `flows_equiv` fs1 /\ fs1 `flows_equiv` fs2 ==> fs0 `flows_equiv` fs2)
= ()
let flows_included_in_union_distr_dest (a b c:label)
: Lemma (flows_equiv [a, union b c] [a, b; a, c])
= ()
let flows_included_in_union_distr_src (a b c:label)
: Lemma (flows_equiv [union a b, c] [a, c; b, c])
= ()
let flows_included_in_union (a b c:label)
: Lemma (flows_equiv ([a, union b c; union a b, c])
([a, b; union a b, c]))
= ()
(* The computation behavior of sequential composition of HIFC
is the same as HST.
This is a step towards defining bind_hifc ... we will | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Sec2.HIFC.hifc a r0 w0 fs0 p q -> y: (x: a -> Sec2.HIFC.hifc b r1 w1 fs1 (r x) (s x))
-> Sec2.HIFC.hst b
(fun s0 -> p s0 /\ (forall (x: a) (s1: Sec2.HIFC.store). q s0 x s1 ==> r x s1))
(fun s0 r s2 -> exists (x: a) (s1: Sec2.HIFC.store). q s0 x s1 /\ s x s1 r s2) | Prims.Tot | [
"total"
] | [] | [
"Sec2.HIFC.label",
"Sec2.HIFC.flows",
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hifc",
"Sec2.HIFC.bind_hst",
"Sec2.HIFC.hst",
"Sec2.HIFC.store",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_Exists"
] | [] | false | false | false | false | false | let bind_ifc'
(#a: Type)
(#b: Type)
(#w0: label)
(#r0: label)
(#w1: label)
(#r1: label)
(#fs0: flows)
(#fs1: flows)
#p
#q
#r
#s
(x: hifc a r0 w0 fs0 p q)
(y: (x: a -> hifc b r1 w1 fs1 (r x) (s x)))
: hst b
(fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2)) =
| bind_hst _ _ _ _ _ _ x y | false |
Hacl.FFDHE.fst | Hacl.FFDHE.ffdhe_shared_secret_precomp | val ffdhe_shared_secret_precomp: a:S.ffdhe_alg ->
DH.ffdhe_shared_secret_precomp_st t_limbs a (DH.ffdhe_len a) (ke a) | val ffdhe_shared_secret_precomp: a:S.ffdhe_alg ->
DH.ffdhe_shared_secret_precomp_st t_limbs a (DH.ffdhe_len a) (ke a) | let ffdhe_shared_secret_precomp a p_r2_n sk pk ss =
let len = DH.ffdhe_len a in
DH.ffdhe_shared_secret_precomp a len (ke a) (ffdhe_check_pk a) (ffdhe_compute_exp a) p_r2_n sk pk ss | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 102,
"end_line": 62,
"start_col": 0,
"start_line": 60
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private
[@CInline]
let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a)
private
[@CInline]
let ffdhe_check_pk (a:S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a)
private
[@CInline]
let ffdhe_compute_exp (a:S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_compute_exp a (DH.ffdhe_len a) (ke a)
let ffdhe_len (a:S.ffdhe_alg) : DH.size_pos = DH.ffdhe_len a
val new_ffdhe_precomp_p: a:S.ffdhe_alg ->
DH.new_ffdhe_precomp_p_st t_limbs a (ffdhe_len a) (ke a)
let new_ffdhe_precomp_p a =
DH.new_ffdhe_precomp_p a (DH.ffdhe_len a) (ke a) (ffdhe_precomp_p a)
val ffdhe_secret_to_public_precomp: a:S.ffdhe_alg ->
DH.ffdhe_secret_to_public_precomp_st t_limbs a (DH.ffdhe_len a) (ke a)
let ffdhe_secret_to_public_precomp a p_r2_n sk pk =
let len = DH.ffdhe_len a in
DH.ffdhe_secret_to_public_precomp a len (ke a) (ffdhe_compute_exp a) p_r2_n sk pk
val ffdhe_secret_to_public: a:S.ffdhe_alg ->
DH.ffdhe_secret_to_public_st t_limbs a (DH.ffdhe_len a) (ke a)
let ffdhe_secret_to_public a sk pk =
let len = DH.ffdhe_len a in
DH.ffdhe_secret_to_public a len (ke a) (ffdhe_secret_to_public_precomp a) (ffdhe_precomp_p a) sk pk
val ffdhe_shared_secret_precomp: a:S.ffdhe_alg -> | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg
-> Hacl.Impl.FFDHE.ffdhe_shared_secret_precomp_st Hacl.FFDHE.t_limbs
a
(Hacl.Impl.FFDHE.ffdhe_len a)
(Hacl.FFDHE.ke a) | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.FFDHE.t_limbs",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.blocks",
"Hacl.Impl.FFDHE.ffdhe_len",
"Lib.IntTypes.size",
"Lib.IntTypes.numbytes",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.FFDHE.ffdhe_shared_secret_precomp",
"Hacl.FFDHE.ke",
"Hacl.FFDHE.ffdhe_check_pk",
"Hacl.FFDHE.ffdhe_compute_exp",
"Hacl.Bignum.Definitions.limb",
"Hacl.Impl.FFDHE.size_pos",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.v",
"Spec.FFDHE.ffdhe_len"
] | [] | false | false | false | false | false | let ffdhe_shared_secret_precomp a p_r2_n sk pk ss =
| let len = DH.ffdhe_len a in
DH.ffdhe_shared_secret_precomp a len (ke a) (ffdhe_check_pk a) (ffdhe_compute_exp a) p_r2_n sk pk ss | false |
Sec2.HIFC.fst | Sec2.HIFC.reads_ok_does_not_read_loc | val reads_ok_does_not_read_loc
(#a #p #q: _)
(f: hst a p q)
(rds: label)
(l: loc{~(Set.mem l rds)})
(s0: store{p s0})
: Lemma (requires reads f rds) (ensures does_not_read_loc f rds l s0) | val reads_ok_does_not_read_loc
(#a #p #q: _)
(f: hst a p q)
(rds: label)
(l: loc{~(Set.mem l rds)})
(s0: store{p s0})
: Lemma (requires reads f rds) (ensures does_not_read_loc f rds l s0) | let reads_ok_does_not_read_loc #a #p #q (f:hst a p q) (rds:label) (l:loc{~(Set.mem l rds)}) (s0:store{p s0})
: Lemma
(requires reads f rds)
(ensures does_not_read_loc f rds l s0)
= let aux (v:int)
: Lemma (requires p (upd s0 l v))
(ensures does_not_read_loc_v f rds l s0 v)
[SMTPat ((upd s0 l v))]
= assert (agree_on rds s0 (upd s0 l v));
()
in
() | {
"file_name": "examples/layeredeffects/Sec2.HIFC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 6,
"end_line": 160,
"start_col": 0,
"start_line": 149
} | module Sec2.HIFC
open FStar.List.Tot
open FStar.Map
let loc = int
type store = m:Map.t loc int{forall l. contains m l}
let upd (s:store) (l:loc) (x:int) : store = Map.upd s l x
let sel (s:store) (l:loc) : int = Map.sel s l
open FStar.Set
(*** A basic Hoare state monad ***)
let pre = store -> Type0
let post a = store -> a -> store -> Type0
let hst a (p:pre) (q:post a) = s0:store{p s0} -> r:(a & store){q s0 (fst r) (snd r)}
let return_hst a (x:a) : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s
let bind_hst (a b:Type)
p q r s
(x:hst a p q)
(y: (x:a -> hst b (r x) (s x)))
: hst b (fun s0 -> p s0 /\ (forall x s1. q s0 x s1 ==> r x s1))
(fun s0 r s2 -> (exists x s1. q s0 x s1 /\ s x s1 r s2))
= fun s0 -> let v, s1 = x s0 in y v s1
let subcomp_hst (a:Type) p q r s (x:hst a p q)
: Pure (hst a r s)
(requires (forall st. r st ==> p st) /\
(forall st0 res st1. q st0 res st1 ==> s st0 res st1))
(ensures fun _ -> True)
= x
let if_then_else_hst (a:Type) p q r s (x:hst a p q) (y:hst a r s) (b:bool) : Type =
hst a (fun st -> (b ==> p st) /\ ((~ b) ==> r st))
(fun st0 res st1 -> (b ==> q st0 res st1) /\ ((~ b) ==> s st0 res st1))
effect {
HST (a:Type) (p:pre) (q:post a)
with {
repr = hst;
return = return_hst;
bind = bind_hst;
subcomp = subcomp_hst;
if_then_else = if_then_else_hst
}
}
(*** Now, HIFC ***)
(* Some basic definitions of labels and sets *)
let label = Set.set loc
let label_inclusion (l0 l1:label) = Set.subset l0 l1
let bot : label = Set.empty
let single (l:loc) : label = Set.singleton l
let union (l0 l1:label) = Set.union l0 l1
let is_empty #a (s:Set.set a) = forall (x:a). ~ (Set.mem x s)
(* The write effect of a computation *)
let modifies (w:label) (s0 s1:store) = (forall l.{:pattern (sel s1 l)} ~(Set.mem l w) ==> sel s0 l == sel s1 l)
let writes #a #p #q (f:hst a p q) (writes:label) =
forall (s0:store{p s0}). let x1, s0' = f s0 in modifies writes s0 s0'
(* The read effect of a computation *)
let agree_on (reads:label) (s0 s1: store) = forall l. Set.mem l reads ==> sel s0 l == sel s1 l
let related_runs #a #p #q (f:hst a p q) (s0:store{p s0}) (s0':store{p s0'}) =
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\
(forall (l:loc). (sel s1 l == sel s1' l \/ (sel s1 l == sel s0 l /\ sel s1' l == sel s0' l))))
let reads #a #p #q (f:hst a p q) (reads:label) =
forall (s0:store{p s0}) (s0':store{p s0'}). agree_on reads s0 s0' ==> related_runs f s0 s0'
(* The respects flows refinement *)
let flow = label & label //from, to
let flows = list flow
let has_flow_1 (from to:loc) (f:flow) = from `Set.mem` fst f /\ to `Set.mem` snd f
let has_flow (from to:loc) (fs:flows) = (exists rs. rs `List.Tot.memP` fs /\ has_flow_1 from to rs)
let no_leakage_k #a #p #q (f:hst a p q) (from to:loc) (k:int) =
forall (s0:store{p s0}).{:pattern (upd s0 from k)}
p (upd s0 from k) ==>
sel (snd (f s0)) to == (sel (snd (f (upd s0 from k))) to)
let no_leakage #a #p #q (f:hst a p q) (from to:loc) = forall k. no_leakage_k f from to k
let respects #a #p #q (f:hst a p q) (fs:flows) =
(forall from to. {:pattern (no_leakage f from to)} ~(has_flow from to fs) /\ from<>to ==> no_leakage f from to)
(** Representation type for the HIFC effect
You should convince yourself that `reads`, `writes` and `respects`
really capture the intended semantics of read effects, write effects, and IFC **)
let hifc a (r:label) (w:label) (fs:flows) (p:pre) (q:post a) =
f:hst a p q {
reads f r /\
writes f w /\
respects f fs
}
(** returning a pure value `x` into hifc **)
let return (a:Type) (x:a) : hifc a bot bot [] (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) =
let f : hst a (fun _ -> True) (fun s0 r s1 -> s0 == s1 /\ r == x) = fun s -> x,s in
f
(** reading a loc `l` *)
let iread (l:loc) : hifc int (single l) bot [] (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) =
let f : hst int (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == sel s0 l) = fun s -> sel s l, s in
f
(** writing a loc `l` *)
let iwrite (l:loc) (x:int) : hifc unit bot (single l) [] (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) =
let f : hst unit (fun _ -> True) (fun s0 _ s1 -> s1 == upd s0 l x) = fun s -> (), upd s l x in
f
(** Now, a lot of what follows is proofs that allow us to define
return, bind, subsumption, and other combinators *)
let does_not_read_loc_v #a #p #q (f:hst a p q)
(reads:label)
(l:loc)
(s0:store{p s0})
v =
let s0' = upd s0 l v in
p s0' ==>
(let x1, s1 = f s0 in
let x1', s1' = f s0' in
x1 == x1' /\ //result does not depend on l
(forall l'. l' <> l ==> //for every location l' not equal to l
sel s1 l' == sel s1' l') /\ //its value in the two states is the same
(sel s1 l == sel s1' l \/ //and l is itself may be written, in which case its value is the same in both final states
//or its not, but then its values in the initial and final states are the same on both sides
(sel s1 l == sel s0 l /\
sel s1' l == sel s0' l)))
let does_not_read_loc #a #p #q (f:hst a p q) (reads:label) (l:loc) (s0:store{p s0}) =
forall v. does_not_read_loc_v f reads l s0 v
let reads_ok_preserves_equal_locs #a #p #q (f:hst a p q) (rds:label) (s0:store{p s0}) (s0':store{p s0'})
: Lemma (requires agree_on rds s0 s0' /\ reads f rds)
(ensures (let x1, s1 = f s0 in
let x1', s1' = f s0' in
agree_on rds s1 s1'))
= ()
let weaken_reads_ok #a #p #q (f:hst a p q) (rds rds1:label)
: Lemma (requires reads f rds /\
label_inclusion rds rds1)
(ensures reads f rds1)
= let aux s0 s0'
: Lemma (requires p s0 /\ p s0' /\ agree_on rds1 s0 s0')
(ensures agree_on rds s0 s0')
[SMTPat(agree_on rds1 s0 s0')]
= ()
in
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Sec2.HIFC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Set",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Sec2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: Sec2.HIFC.hst a p q ->
rds: Sec2.HIFC.label ->
l: Sec2.HIFC.loc{~(FStar.Set.mem l rds)} ->
s0: Sec2.HIFC.store{p s0}
-> FStar.Pervasives.Lemma (requires Sec2.HIFC.reads f rds)
(ensures Sec2.HIFC.does_not_read_loc f rds l s0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Sec2.HIFC.pre",
"Sec2.HIFC.post",
"Sec2.HIFC.hst",
"Sec2.HIFC.label",
"Sec2.HIFC.loc",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Sec2.HIFC.store",
"Prims.int",
"Prims.unit",
"Sec2.HIFC.upd",
"Prims.squash",
"Sec2.HIFC.does_not_read_loc_v",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"Prims._assert",
"Sec2.HIFC.agree_on",
"Sec2.HIFC.reads",
"Sec2.HIFC.does_not_read_loc"
] | [] | false | false | true | false | false | let reads_ok_does_not_read_loc
#a
#p
#q
(f: hst a p q)
(rds: label)
(l: loc{~(Set.mem l rds)})
(s0: store{p s0})
: Lemma (requires reads f rds) (ensures does_not_read_loc f rds l s0) =
| let aux (v: int)
: Lemma (requires p (upd s0 l v))
(ensures does_not_read_loc_v f rds l s0 v)
[SMTPat ((upd s0 l v))] =
assert (agree_on rds s0 (upd s0 l v));
()
in
() | false |
Hacl.Ed25519.fst | Hacl.Ed25519.sign | val sign:
signature:lbuffer uint8 64ul
-> private_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len ->
Stack unit
(requires fun h ->
live h signature /\ live h msg /\ live h private_key /\
disjoint signature msg /\ disjoint signature private_key)
(ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\
as_seq h1 signature == Spec.Ed25519.sign (as_seq h0 private_key) (as_seq h0 msg)) | val sign:
signature:lbuffer uint8 64ul
-> private_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len ->
Stack unit
(requires fun h ->
live h signature /\ live h msg /\ live h private_key /\
disjoint signature msg /\ disjoint signature private_key)
(ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\
as_seq h1 signature == Spec.Ed25519.sign (as_seq h0 private_key) (as_seq h0 msg)) | let sign signature private_key msg_len msg =
push_frame ();
let expanded_keys = create 96ul (u8 0) in
expand_keys expanded_keys private_key;
sign_expanded signature expanded_keys msg_len msg;
pop_frame () | {
"file_name": "code/ed25519/Hacl.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 58,
"start_col": 0,
"start_line": 53
} | module Hacl.Ed25519
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module S = Spec.Ed25519
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit
(requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret)
(ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\
(let a, prefix = S.secret_expand (as_seq h0 secret) in
as_seq h1 (gsub expanded 0ul 32ul) == a /\
as_seq h1 (gsub expanded 32ul 32ul) == prefix))
[@CInline]
let secret_expand expanded secret =
assert_norm (pow2 32 <= pow2 125 - 1);
Hacl.Streaming.SHA2.hash_512 expanded secret 32ul;
let h_low = sub expanded 0ul 32ul in
let h_low0 = h_low.( 0ul) in
let h_low31 = h_low.(31ul) in
h_low.( 0ul) <- h_low0 &. u8 0xf8;
h_low.(31ul) <- (h_low31 &. u8 127) |. u8 64
let secret_to_public public_key private_key =
push_frame ();
let expanded_secret = create 64ul (u8 0) in
secret_expand expanded_secret private_key;
let a = sub expanded_secret 0ul 32ul in
Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key a;
pop_frame ()
let expand_keys expanded_keys private_key =
let public_key = sub expanded_keys 0ul 32ul in
let s_prefix = sub expanded_keys 32ul 64ul in
let s = sub expanded_keys 32ul 32ul in
secret_expand s_prefix private_key;
Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key s
let sign_expanded signature expanded_keys msg_len msg =
Hacl.Impl.Ed25519.Sign.sign_expanded signature expanded_keys msg_len msg | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Impl.Ed25519.Verify.fst.checked",
"Hacl.Impl.Ed25519.Sign.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
private_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
msg_len: Lib.IntTypes.size_t ->
msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Ed25519.sign_expanded",
"Hacl.Ed25519.expand_keys",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let sign signature private_key msg_len msg =
| push_frame ();
let expanded_keys = create 96ul (u8 0) in
expand_keys expanded_keys private_key;
sign_expanded signature expanded_keys msg_len msg;
pop_frame () | false |
ContextPollution.fst | ContextPollution.warmup2 | val warmup2 : x: Prims.bool{x == true} -> Prims.unit | let warmup2 (x:bool { x == true }) = assert x | {
"file_name": "share/steel/tests/ContextPollution.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | module ContextPollution
let warmup (x:bool { x == true }) = assert x
//SNIPPET_START: context_test1$
module T = FStar.Tactics
module B = LowStar.Buffer
module SA = Steel.Array
open FStar.Seq
#push-options "--query_stats"
let warmup1 (x:bool { x == true }) = assert x
let test1 (a:Type) (s0 s1 s2: seq a)
: Lemma (Seq.append (Seq.append s0 s1) s2 `Seq.equal`
Seq.append s0 (Seq.append s1 s2))
= ()
//SNIPPET_END: context_test1$
//SNIPPET_START: using_facts$ | {
"checked_file": "/",
"dependencies": [
"Steel.Array.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "ContextPollution.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Array",
"short_module": "SA"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.bool{x == true} -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.eq2",
"Prims._assert",
"Prims.b2t",
"Prims.unit"
] | [] | false | false | false | false | false | let warmup2 (x: bool{x == true}) =
| assert x | false |
|
Hacl.FFDHE.fst | Hacl.FFDHE.ffdhe_secret_to_public_precomp | val ffdhe_secret_to_public_precomp: a:S.ffdhe_alg ->
DH.ffdhe_secret_to_public_precomp_st t_limbs a (DH.ffdhe_len a) (ke a) | val ffdhe_secret_to_public_precomp: a:S.ffdhe_alg ->
DH.ffdhe_secret_to_public_precomp_st t_limbs a (DH.ffdhe_len a) (ke a) | let ffdhe_secret_to_public_precomp a p_r2_n sk pk =
let len = DH.ffdhe_len a in
DH.ffdhe_secret_to_public_precomp a len (ke a) (ffdhe_compute_exp a) p_r2_n sk pk | {
"file_name": "code/ffdhe/Hacl.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 48,
"start_col": 0,
"start_line": 46
} | module Hacl.FFDHE
open Lib.IntTypes
module S = Spec.FFDHE
module DH = Hacl.Impl.FFDHE
module BD = Hacl.Bignum.Definitions
module BE = Hacl.Bignum.Exponentiation
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs = U64
inline_for_extraction noextract
let ke (a:S.ffdhe_alg) =
BE.mk_runtime_exp #t_limbs (BD.blocks (DH.ffdhe_len a) (size (numbytes t_limbs)))
private
[@CInline]
let ffdhe_precomp_p (a:S.ffdhe_alg) : DH.ffdhe_precomp_p_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_precomp_p a (DH.ffdhe_len a) (ke a)
private
[@CInline]
let ffdhe_check_pk (a:S.ffdhe_alg) : DH.ffdhe_check_pk_st t_limbs a (DH.ffdhe_len a) =
DH.ffdhe_check_pk #t_limbs a (DH.ffdhe_len a)
private
[@CInline]
let ffdhe_compute_exp (a:S.ffdhe_alg) : DH.ffdhe_compute_exp_st t_limbs a (DH.ffdhe_len a) (ke a) =
DH.ffdhe_compute_exp a (DH.ffdhe_len a) (ke a)
let ffdhe_len (a:S.ffdhe_alg) : DH.size_pos = DH.ffdhe_len a
val new_ffdhe_precomp_p: a:S.ffdhe_alg ->
DH.new_ffdhe_precomp_p_st t_limbs a (ffdhe_len a) (ke a)
let new_ffdhe_precomp_p a =
DH.new_ffdhe_precomp_p a (DH.ffdhe_len a) (ke a) (ffdhe_precomp_p a)
val ffdhe_secret_to_public_precomp: a:S.ffdhe_alg -> | {
"checked_file": "/",
"dependencies": [
"Spec.FFDHE.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.FFDHE.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.FFDHE.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.FFDHE",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.FFDHE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.FFDHE.ffdhe_alg
-> Hacl.Impl.FFDHE.ffdhe_secret_to_public_precomp_st Hacl.FFDHE.t_limbs
a
(Hacl.Impl.FFDHE.ffdhe_len a)
(Hacl.FFDHE.ke a) | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.ffdhe_alg",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.FFDHE.t_limbs",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.blocks",
"Hacl.Impl.FFDHE.ffdhe_len",
"Lib.IntTypes.size",
"Lib.IntTypes.numbytes",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.FFDHE.ffdhe_secret_to_public_precomp",
"Hacl.FFDHE.ke",
"Hacl.FFDHE.ffdhe_compute_exp",
"Prims.unit",
"Hacl.Impl.FFDHE.size_pos",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.l_and",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.v",
"Spec.FFDHE.ffdhe_len"
] | [] | false | false | false | false | false | let ffdhe_secret_to_public_precomp a p_r2_n sk pk =
| let len = DH.ffdhe_len a in
DH.ffdhe_secret_to_public_precomp a len (ke a) (ffdhe_compute_exp a) p_r2_n sk pk | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.