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
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.l_pre
val l_pre : pre: Mkst0?.hprop st -> Type
let l_pre (#st:st) (pre:st.hprop) = fp_prop pre
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 221, "start_col": 0, "start_line": 221 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pre: Mkst0?.hprop st -> Type
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.fp_prop" ]
[]
false
false
false
false
true
let l_pre (#st: st) (pre: st.hprop) =
fp_prop pre
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.depends_only_on2
val depends_only_on2 : q: (_: Mkst0?.mem st -> _: a -> _: Mkst0?.mem st -> Prims.prop) -> fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Prims.logical
let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 68, "end_line": 270, "start_col": 0, "start_line": 263 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: (_: Mkst0?.mem st -> _: a -> _: Mkst0?.mem st -> Prims.prop) -> fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.depends_only_on_0_2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.logical" ]
[]
false
false
false
false
true
let depends_only_on2 (#st: st0) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp_pre: st.hprop) (fp_post: (a -> st.hprop)) =
depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.fp_prop2
val fp_prop2 : fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Type
let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post}
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 70, "end_line": 273, "start_col": 0, "start_line": 272 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
fp_pre: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> Type
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.depends_only_on2" ]
[]
false
false
false
false
true
let fp_prop2 (#st: st0) (#a: Type) (fp_pre: st.hprop) (fp_post: (a -> st.hprop)) =
q: (st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post}
false
Hacl.HPKE.Interface.HKDF.fst
Hacl.HPKE.Interface.HKDF.hkdf_expand256
val hkdf_expand256:HK.expand_st Hash.SHA2_256
val hkdf_expand256:HK.expand_st Hash.SHA2_256
let hkdf_expand256 : HK.expand_st Hash.SHA2_256 = Hacl.HKDF.expand_sha2_256
{ "file_name": "code/hpke/Hacl.HPKE.Interface.HKDF.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 75, "end_line": 28, "start_col": 0, "start_line": 28 }
module Hacl.HPKE.Interface.HKDF module S = Spec.Agile.HPKE module HK = Hacl.HKDF module Hash = Spec.Agile.Hash [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract: #cs:S.ciphersuite -> HK.extract_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand: #cs:S.ciphersuite -> HK.expand_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract_kem: #cs:S.ciphersuite -> HK.extract_st (S.kem_hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand_kem: #cs:S.ciphersuite -> HK.expand_st (S.kem_hash_of_cs cs) (** Instantiations of hkdf **) inline_for_extraction noextract let hkdf_extract256 : HK.extract_st Hash.SHA2_256 = Hacl.HKDF.extract_sha2_256
{ "checked_file": "/", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.HKDF.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Hacl.HKDF", "short_module": "HK" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "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": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HKDF.expand_st Spec.Hash.Definitions.SHA2_256
Prims.Tot
[ "total" ]
[]
[ "Hacl.HKDF.expand_sha2_256" ]
[]
false
false
false
true
false
let hkdf_expand256:HK.expand_st Hash.SHA2_256 =
Hacl.HKDF.expand_sha2_256
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.fp_prop_0_2
val fp_prop_0_2 : interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> fp_pre: hprop -> fp_post: (_: a -> hprop) -> Type
let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post}
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 90, "end_line": 261, "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 Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
interp: (_: hprop -> _: heap -> Prims.prop) -> disjoint: (_: heap -> _: heap -> Prims.prop) -> join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap) -> fp_pre: hprop -> fp_post: (_: a -> hprop) -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.prop", "Steel.Semantics.Hoare.MST.depends_only_on_0_2" ]
[]
false
false
false
false
true
let fp_prop_0_2 (#a #heap #hprop: Type) (interp: (hprop -> heap -> prop)) (disjoint: (heap -> heap -> prop)) (join: (h0: heap -> h1: heap{disjoint h0 h1} -> heap)) (fp_pre: hprop) (fp_post: (a -> hprop)) =
q: (heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post}
false
Hacl.HPKE.Interface.HKDF.fst
Hacl.HPKE.Interface.HKDF.hkdf_extract512
val hkdf_extract512:HK.extract_st Hash.SHA2_512
val hkdf_extract512:HK.extract_st Hash.SHA2_512
let hkdf_extract512 : HK.extract_st Hash.SHA2_512 = Hacl.HKDF.extract_sha2_512
{ "file_name": "code/hpke/Hacl.HPKE.Interface.HKDF.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 31, "start_col": 0, "start_line": 31 }
module Hacl.HPKE.Interface.HKDF module S = Spec.Agile.HPKE module HK = Hacl.HKDF module Hash = Spec.Agile.Hash [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract: #cs:S.ciphersuite -> HK.extract_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand: #cs:S.ciphersuite -> HK.expand_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract_kem: #cs:S.ciphersuite -> HK.extract_st (S.kem_hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand_kem: #cs:S.ciphersuite -> HK.expand_st (S.kem_hash_of_cs cs) (** Instantiations of hkdf **) inline_for_extraction noextract let hkdf_extract256 : HK.extract_st Hash.SHA2_256 = Hacl.HKDF.extract_sha2_256 inline_for_extraction noextract let hkdf_expand256 : HK.expand_st Hash.SHA2_256 = Hacl.HKDF.expand_sha2_256
{ "checked_file": "/", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.HKDF.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Hacl.HKDF", "short_module": "HK" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "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": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HKDF.extract_st Spec.Hash.Definitions.SHA2_512
Prims.Tot
[ "total" ]
[]
[ "Hacl.HKDF.extract_sha2_512" ]
[]
false
false
false
true
false
let hkdf_extract512:HK.extract_st Hash.SHA2_512 =
Hacl.HKDF.extract_sha2_512
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.post_preserves_frame
val post_preserves_frame : post: Mkst0?.hprop st -> frame: Mkst0?.hprop st -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1))
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 80, "end_line": 306, "start_col": 0, "start_line": 304 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
post: Mkst0?.hprop st -> frame: Mkst0?.hprop st -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_prop", "Prims.eq2", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.logical" ]
[]
false
false
false
false
true
let post_preserves_frame (#st: st) (post frame: st.hprop) (m0 m1: st.mem) =
st.interp ((post `st.star` frame) `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame: fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1))
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.full_mem
val full_mem : st: Steel.Semantics.Hoare.MST.st -> Type
let full_mem (st:st) = m:st.mem{st.full_mem_pred m}
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 284, "start_col": 0, "start_line": 284 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Steel.Semantics.Hoare.MST.st -> Type
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__full_mem_pred" ]
[]
false
false
false
true
true
let full_mem (st: st) =
m: st.mem{st.full_mem_pred m}
false
Hacl.Test.SHA2.fst
Hacl.Test.SHA2.test3_expected_sha2_512
val test3_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
val test3_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 216, "start_col": 0, "start_line": 206 }
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (64ul <: FStar.UInt32.t) {Lib.Buffer.recallable b}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
false
false
let test3_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} =
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45 ]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.l_post
val l_post : pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> Type
let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 83, "end_line": 277, "start_col": 0, "start_line": 277 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> Type
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.fp_prop2" ]
[]
false
false
false
false
true
let l_post (#st: st) (#a: Type) (pre: st.hprop) (post: post_t st a) =
fp_prop2 pre post
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.action_t_tot
val action_t_tot : pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 338, "start_col": 0, "start_line": 324 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.post_preserves_frame" ]
[]
false
false
false
false
true
let action_t_tot (#st: st) (#a: Type) (pre: st.hprop) (post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) =
frame: st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` (st.locks_invariant m0)) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
false
Hacl.Test.SHA2.fst
Hacl.Test.SHA2.test3_expected_sha2_384
val test3_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
val test3_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 204, "start_col": 0, "start_line": 195 }
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (48ul <: FStar.UInt32.t) {Lib.Buffer.recallable b}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
false
false
let test3_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} =
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b ]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
false
Hacl.HPKE.Interface.HKDF.fst
Hacl.HPKE.Interface.HKDF.hkdf_expand512
val hkdf_expand512:HK.expand_st Hash.SHA2_512
val hkdf_expand512:HK.expand_st Hash.SHA2_512
let hkdf_expand512 : HK.expand_st Hash.SHA2_512 = Hacl.HKDF.expand_sha2_512
{ "file_name": "code/hpke/Hacl.HPKE.Interface.HKDF.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 75, "end_line": 33, "start_col": 0, "start_line": 33 }
module Hacl.HPKE.Interface.HKDF module S = Spec.Agile.HPKE module HK = Hacl.HKDF module Hash = Spec.Agile.Hash [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract: #cs:S.ciphersuite -> HK.extract_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand: #cs:S.ciphersuite -> HK.expand_st (S.hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_extract_kem: #cs:S.ciphersuite -> HK.extract_st (S.kem_hash_of_cs cs) [@ Meta.Attribute.specialize ] noextract assume val hkdf_expand_kem: #cs:S.ciphersuite -> HK.expand_st (S.kem_hash_of_cs cs) (** Instantiations of hkdf **) inline_for_extraction noextract let hkdf_extract256 : HK.extract_st Hash.SHA2_256 = Hacl.HKDF.extract_sha2_256 inline_for_extraction noextract let hkdf_expand256 : HK.expand_st Hash.SHA2_256 = Hacl.HKDF.expand_sha2_256 inline_for_extraction noextract let hkdf_extract512 : HK.extract_st Hash.SHA2_512 = Hacl.HKDF.extract_sha2_512
{ "checked_file": "/", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Hacl.HKDF.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.HKDF.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Hacl.HKDF", "short_module": "HK" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "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": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HKDF.expand_st Spec.Hash.Definitions.SHA2_512
Prims.Tot
[ "total" ]
[]
[ "Hacl.HKDF.expand_sha2_512" ]
[]
false
false
false
true
false
let hkdf_expand512:HK.expand_st Hash.SHA2_512 =
Hacl.HKDF.expand_sha2_512
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.action_t
val action_t : pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 322, "start_col": 0, "start_line": 308 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pre: Mkst0?.hprop st -> post: Steel.Semantics.Hoare.MST.post_t st a -> lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> Type
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.post_preserves_frame" ]
[]
false
false
false
false
true
let action_t (#st: st) (#a: Type) (pre: st.hprop) (post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) =
frame: st.hprop -> Mst a (requires fun m0 -> st.interp ((pre `st.star` frame) `st.star` (st.locks_invariant m0)) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1))
false
Hacl.Test.SHA2.fst
Hacl.Test.SHA2.test4_expected_sha2_384
val test4_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
val test4_expected_sha2_384:b: lbuffer uint8 48ul {recallable b}
let test4_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 265, "start_col": 0, "start_line": 256 }
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test4_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (48ul <: FStar.UInt32.t) {Lib.Buffer.recallable b}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
false
false
let test4_expected_sha2_384:b: lbuffer uint8 48ul {recallable b} =
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39 ]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.disjoint_join
val disjoint_join : st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 145, "start_col": 0, "start_line": 138 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st0", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Prims.l_and", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.logical" ]
[]
false
false
false
true
true
let disjoint_join (st: st0) =
forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.weaker_pre
val weaker_pre : pre: Mkst0?.hprop st -> next_pre: Mkst0?.hprop st -> Prims.logical
let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 433, "start_col": 0, "start_line": 430 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pre: Mkst0?.hprop st -> next_pre: Mkst0?.hprop st -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.logical" ]
[]
false
false
false
false
true
let weaker_pre (#st: st) (pre next_pre: st.hprop) =
forall (h: st.mem) (frame: st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.join_associative
val join_associative : st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_join st} -> Prims.logical
let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 60, "end_line": 156, "start_col": 0, "start_line": 152 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_join st} -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.disjoint_join", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.l_imp", "Prims.eq2", "Prims.logical" ]
[]
false
false
false
false
true
let join_associative (st: st0{disjoint_join st}) =
forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.weakening_ok
val weakening_ok : lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> wlpre: Steel.Semantics.Hoare.MST.l_pre wpre -> wlpost: Steel.Semantics.Hoare.MST.l_post wpre wpost -> Prims.logical
let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 52, "end_line": 455, "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 Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> wlpre: Steel.Semantics.Hoare.MST.l_pre wpre -> wlpost: Steel.Semantics.Hoare.MST.l_post wpre wpost -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Prims.l_and", "Steel.Semantics.Hoare.MST.weaker_pre", "Steel.Semantics.Hoare.MST.stronger_post", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_imp", "Prims.logical" ]
[]
false
false
false
false
true
let weakening_ok (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#wpre: st.hprop) (#wpost: post_t st a) (wlpre: l_pre wpre) (wlpost: l_post wpre wpost) =
weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.join_commutative
val join_commutative : st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_sym st} -> Prims.logical
let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 150, "start_col": 0, "start_line": 147 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Steel.Semantics.Hoare.MST.st0{Steel.Semantics.Hoare.MST.disjoint_sym st} -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st0", "Steel.Semantics.Hoare.MST.disjoint_sym", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__disjoint", "Prims.l_imp", "Prims.eq2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__join", "Prims.logical" ]
[]
false
false
false
false
true
let join_commutative (st: st0{disjoint_sym st}) =
forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0
false
Hacl.Test.SHA2.fst
Hacl.Test.SHA2.test4_plaintext
val test4_plaintext:b: lbuffer uint8 112ul {recallable b}
val test4_plaintext:b: lbuffer uint8 112ul {recallable b}
let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 234, "start_col": 0, "start_line": 221 }
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (112ul <: FStar.UInt32.t) {Lib.Buffer.recallable b}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
false
false
let test4_plaintext:b: lbuffer uint8 112ul {recallable b} =
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75 ]) in assert_norm (List.Tot.length l == 112); createL_mglobal l
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.stronger_lpost
val stronger_lpost : lpost: Steel.Semantics.Hoare.MST.l_post pre post -> next_lpost: Steel.Semantics.Hoare.MST.l_post next_pre next_post -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 618, "start_col": 0, "start_line": 605 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpost: Steel.Semantics.Hoare.MST.l_post pre post -> next_lpost: Steel.Semantics.Hoare.MST.l_post next_pre next_post -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_Forall", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.logical" ]
[]
false
false
false
false
true
let stronger_lpost (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (#next_pre: st.hprop) #next_post (next_lpost: l_post next_pre next_post) (m0: st.mem) (m1: st.mem) =
forall (x: a) (h_final: st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.stronger_post
val stronger_post : post: Steel.Semantics.Hoare.MST.post_t st a -> next_post: Steel.Semantics.Hoare.MST.post_t st a -> Prims.logical
let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 438, "start_col": 0, "start_line": 435 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
post: Steel.Semantics.Hoare.MST.post_t st a -> next_post: Steel.Semantics.Hoare.MST.post_t st a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.post_t", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.logical" ]
[]
false
false
false
false
true
let stronger_post (#st: st) (#a: Type u#a) (post next_post: post_t st a) =
forall (x: a) (h: st.mem) (frame: st.hprop). st.interp ((next_post x) `st.star` frame) h ==> st.interp ((post x) `st.star` frame) h
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.st_laws
val st_laws : st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 199, "start_col": 0, "start_line": 183 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Steel.Semantics.Hoare.MST.st0 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st0", "Prims.l_and", "Steel.Semantics.Hoare.MST.symmetry", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.transitive", "Steel.Semantics.Hoare.MST.interp_extensionality", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.associative", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.commutative", "Steel.Semantics.Hoare.MST.is_unit", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__emp", "Steel.Semantics.Hoare.MST.equals_ext", "Steel.Semantics.Hoare.MST.affine", "Steel.Semantics.Hoare.MST.disjoint_sym", "Steel.Semantics.Hoare.MST.disjoint_join", "Steel.Semantics.Hoare.MST.join_commutative", "Steel.Semantics.Hoare.MST.join_associative", "Prims.logical" ]
[]
false
false
false
true
true
let st_laws (st: st0) =
symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ affine st /\ disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_req
val step_req: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> Type0
val step_req: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> Type0
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 593, "start_col": 0, "start_line": 581 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost -> _: Mkst0?.mem st -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core" ]
[]
false
false
false
false
true
let step_req (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost) : st.mem -> Type0 =
fun m0 -> st.interp ((pre `st.star` frame) `st.star` (st.locks_invariant m0)) m0 /\ lpre (st.core m0)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.weaker_lpre
val weaker_lpre : lpre: Steel.Semantics.Hoare.MST.l_pre pre -> next_lpre: Steel.Semantics.Hoare.MST.l_pre next_pre -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 46, "end_line": 603, "start_col": 0, "start_line": 595 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> next_lpre: Steel.Semantics.Hoare.MST.l_pre next_pre -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_imp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.logical" ]
[]
false
false
false
false
true
let weaker_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#next_pre: st.hprop) (next_lpre: l_pre next_pre) (m0 m1: st.mem) =
lpre (st.core m0) ==> next_lpre (st.core m1)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_ens
val step_ens: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> step_result st a -> st.mem -> Type0
val step_ens: #st: st -> #a: Type u#a -> #pre: st.hprop -> #post: post_t st a -> #lpre: l_pre pre -> #lpost: l_post pre post -> frame: st.hprop -> f: m st a pre post lpre lpost -> st.mem -> step_result st a -> st.mem -> Type0
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 639, "start_col": 0, "start_line": 621 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost -> _: Mkst0?.mem st -> _: Steel.Semantics.Hoare.MST.step_result st a -> _: Mkst0?.mem st -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.step_result", "Prims.l_and", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.stronger_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.weaker_lpre", "Steel.Semantics.Hoare.MST.stronger_lpost" ]
[]
false
false
false
false
true
let step_ens (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 =
fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.get
val get: #st: st -> Prims.unit -> MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
val get: #st: st -> Prims.unit -> MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get ()
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 10, "end_line": 296, "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 Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Steel.Semantics.Hoare.MST.MstTot (Steel.Semantics.Hoare.MST.full_mem st)
Steel.Semantics.Hoare.MST.MstTot
[]
[]
[ "Steel.Semantics.Hoare.MST.st", "Prims.unit", "FStar.NMSTTotal.get", "Steel.Semantics.Hoare.MST.full_mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_True", "Prims.l_and", "Prims.eq2" ]
[]
false
true
false
false
false
let get (#st: st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) =
get ()
false
Hacl.Test.SHA2.fst
Hacl.Test.SHA2.main
val main: unit -> St C.exit_code
val main: unit -> St C.exit_code
let main () = C.String.print (C.String.of_literal "\nTEST 1. SHA2\n"); recall test1_expected_sha2_224; recall test1_expected_sha2_256; recall test1_expected_sha2_384; recall test1_expected_sha2_512; recall test1_plaintext; test_sha2 3ul test1_plaintext test1_expected_sha2_224 test1_expected_sha2_256 test1_expected_sha2_384 test1_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 2. SHA2\n"); recall test2_expected_sha2_224; recall test2_expected_sha2_256; recall test2_expected_sha2_384; recall test2_expected_sha2_512; recall test2_plaintext; test_sha2 0ul test2_plaintext test2_expected_sha2_224 test2_expected_sha2_256 test2_expected_sha2_384 test2_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 3. SHA2\n"); recall test3_expected_sha2_224; recall test3_expected_sha2_256; recall test3_expected_sha2_384; recall test3_expected_sha2_512; recall test3_plaintext; test_sha2 56ul test3_plaintext test3_expected_sha2_224 test3_expected_sha2_256 test3_expected_sha2_384 test3_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 4. SHA2\n"); recall test4_expected_sha2_224; recall test4_expected_sha2_256; recall test4_expected_sha2_384; recall test4_expected_sha2_512; recall test4_plaintext; test_sha2 112ul test4_plaintext test4_expected_sha2_224 test4_expected_sha2_256 test4_expected_sha2_384 test4_expected_sha2_512; C.EXIT_SUCCESS
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 333, "start_col": 0, "start_line": 280 }
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test4_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test4_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test4_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x8e; 0x95; 0x9b; 0x75; 0xda; 0xe3; 0x13; 0xda; 0x8c; 0xf4; 0xf7; 0x28; 0x14; 0xfc; 0x14; 0x3f; 0x8f; 0x77; 0x79; 0xc6; 0xeb; 0x9f; 0x7f; 0xa1; 0x72; 0x99; 0xae; 0xad; 0xb6; 0x88; 0x90; 0x18; 0x50; 0x1d; 0x28; 0x9e; 0x49; 0x00; 0xf7; 0xe4; 0x33; 0x1b; 0x99; 0xde; 0xc4; 0xb5; 0x43; 0x3a; 0xc7; 0xd3; 0x29; 0xee; 0xb6; 0xdd; 0x26; 0x54; 0x5e; 0x96; 0xe5; 0x5b; 0x87; 0x4b; 0xe9; 0x09]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.HyperStack.ST.St C.exit_code
FStar.HyperStack.ST.St
[]
[]
[ "Prims.unit", "C.EXIT_SUCCESS", "C.exit_code", "Hacl.Test.SHA2.test_sha2", "FStar.UInt32.__uint_to_t", "Hacl.Test.SHA2.test4_plaintext", "Hacl.Test.SHA2.test4_expected_sha2_224", "Hacl.Test.SHA2.test4_expected_sha2_256", "Hacl.Test.SHA2.test4_expected_sha2_384", "Hacl.Test.SHA2.test4_expected_sha2_512", "Lib.Buffer.recall", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "C.String.print", "C.String.of_literal", "Hacl.Test.SHA2.test3_plaintext", "Hacl.Test.SHA2.test3_expected_sha2_224", "Hacl.Test.SHA2.test3_expected_sha2_256", "Hacl.Test.SHA2.test3_expected_sha2_384", "Hacl.Test.SHA2.test3_expected_sha2_512", "Hacl.Test.SHA2.test2_plaintext", "Hacl.Test.SHA2.test2_expected_sha2_224", "Hacl.Test.SHA2.test2_expected_sha2_256", "Hacl.Test.SHA2.test2_expected_sha2_384", "Hacl.Test.SHA2.test2_expected_sha2_512", "Hacl.Test.SHA2.test1_plaintext", "Hacl.Test.SHA2.test1_expected_sha2_224", "Hacl.Test.SHA2.test1_expected_sha2_256", "Hacl.Test.SHA2.test1_expected_sha2_384", "Hacl.Test.SHA2.test1_expected_sha2_512" ]
[]
false
true
false
false
false
let main () =
C.String.print (C.String.of_literal "\nTEST 1. SHA2\n"); recall test1_expected_sha2_224; recall test1_expected_sha2_256; recall test1_expected_sha2_384; recall test1_expected_sha2_512; recall test1_plaintext; test_sha2 3ul test1_plaintext test1_expected_sha2_224 test1_expected_sha2_256 test1_expected_sha2_384 test1_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 2. SHA2\n"); recall test2_expected_sha2_224; recall test2_expected_sha2_256; recall test2_expected_sha2_384; recall test2_expected_sha2_512; recall test2_plaintext; test_sha2 0ul test2_plaintext test2_expected_sha2_224 test2_expected_sha2_256 test2_expected_sha2_384 test2_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 3. SHA2\n"); recall test3_expected_sha2_224; recall test3_expected_sha2_256; recall test3_expected_sha2_384; recall test3_expected_sha2_512; recall test3_plaintext; test_sha2 56ul test3_plaintext test3_expected_sha2_224 test3_expected_sha2_256 test3_expected_sha2_384 test3_expected_sha2_512; C.String.print (C.String.of_literal "\nTEST 4. SHA2\n"); recall test4_expected_sha2_224; recall test4_expected_sha2_256; recall test4_expected_sha2_384; recall test4_expected_sha2_512; recall test4_plaintext; test_sha2 112ul test4_plaintext test4_expected_sha2_224 test4_expected_sha2_256 test4_expected_sha2_384 test4_expected_sha2_512; C.EXIT_SUCCESS
false
Hacl.Test.SHA2.fst
Hacl.Test.SHA2.test4_expected_sha2_512
val test4_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
val test4_expected_sha2_512:b: lbuffer uint8 64ul {recallable b}
let test4_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x8e; 0x95; 0x9b; 0x75; 0xda; 0xe3; 0x13; 0xda; 0x8c; 0xf4; 0xf7; 0x28; 0x14; 0xfc; 0x14; 0x3f; 0x8f; 0x77; 0x79; 0xc6; 0xeb; 0x9f; 0x7f; 0xa1; 0x72; 0x99; 0xae; 0xad; 0xb6; 0x88; 0x90; 0x18; 0x50; 0x1d; 0x28; 0x9e; 0x49; 0x00; 0xf7; 0xe4; 0x33; 0x1b; 0x99; 0xde; 0xc4; 0xb5; 0x43; 0x3a; 0xc7; 0xd3; 0x29; 0xee; 0xb6; 0xdd; 0x26; 0x54; 0x5e; 0x96; 0xe5; 0x5b; 0x87; 0x4b; 0xe9; 0x09]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 277, "start_col": 0, "start_line": 267 }
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True) let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame() inline_for_extraction noextract val u8: n:nat{n < 0x100} -> uint8 let u8 n = u8 n // // Test1_SHA2 // let test1_plaintext: b:lbuffer uint8 3ul{ recallable b } = let open Lib.RawIntTypes in [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63]) in assert_norm (List.Tot.length l == 3); createL_mglobal l let test1_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x23; 0x09; 0x7d; 0x22; 0x34; 0x05; 0xd8; 0x22; 0x86; 0x42; 0xa4; 0x77; 0xbd; 0xa2; 0x55; 0xb3; 0x2a; 0xad; 0xbc; 0xe4; 0xbd; 0xa0; 0xb3; 0xf7; 0xe3; 0x6c; 0x9d; 0xa7]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test1_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xba; 0x78; 0x16; 0xbf; 0x8f; 0x01; 0xcf; 0xea; 0x41; 0x41; 0x40; 0xde; 0x5d; 0xae; 0x22; 0x23; 0xb0; 0x03; 0x61; 0xa3; 0x96; 0x17; 0x7a; 0x9c; 0xb4; 0x10; 0xff; 0x61; 0xf2; 0x00; 0x15; 0xad]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test1_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcb; 0x00; 0x75; 0x3f; 0x45; 0xa3; 0x5e; 0x8b; 0xb5; 0xa0; 0x3d; 0x69; 0x9a; 0xc6; 0x50; 0x07; 0x27; 0x2c; 0x32; 0xab; 0x0e; 0xde; 0xd1; 0x63; 0x1a; 0x8b; 0x60; 0x5a; 0x43; 0xff; 0x5b; 0xed; 0x80; 0x86; 0x07; 0x2b; 0xa1; 0xe7; 0xcc; 0x23; 0x58; 0xba; 0xec; 0xa1; 0x34; 0xc8; 0x25; 0xa7]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test1_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xdd; 0xaf; 0x35; 0xa1; 0x93; 0x61; 0x7a; 0xba; 0xcc; 0x41; 0x73; 0x49; 0xae; 0x20; 0x41; 0x31; 0x12; 0xe6; 0xfa; 0x4e; 0x89; 0xa9; 0x7e; 0xa2; 0x0a; 0x9e; 0xee; 0xe6; 0x4b; 0x55; 0xd3; 0x9a; 0x21; 0x92; 0x99; 0x2a; 0x27; 0x4f; 0xc1; 0xa8; 0x36; 0xba; 0x3c; 0x23; 0xa3; 0xfe; 0xeb; 0xbd; 0x45; 0x4d; 0x44; 0x23; 0x64; 0x3c; 0xe8; 0x0e; 0x2a; 0x9a; 0xc9; 0x4f; 0xa5; 0x4c; 0xa4; 0x9f]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test2_SHA2 // let test2_plaintext: b:lbuffer uint8 0ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 []) in assert_norm (List.Tot.length l == 0); createL_mglobal l let test2_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xd1; 0x4a; 0x02; 0x8c; 0x2a; 0x3a; 0x2b; 0xc9; 0x47; 0x61; 0x02; 0xbb; 0x28; 0x82; 0x34; 0xc4; 0x15; 0xa2; 0xb0; 0x1f; 0x82; 0x8e; 0xa6; 0x2a; 0xc5; 0xb3; 0xe4; 0x2f]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test2_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xe3; 0xb0; 0xc4; 0x42; 0x98; 0xfc; 0x1c; 0x14; 0x9a; 0xfb; 0xf4; 0xc8; 0x99; 0x6f; 0xb9; 0x24; 0x27; 0xae; 0x41; 0xe4; 0x64; 0x9b; 0x93; 0x4c; 0xa4; 0x95; 0x99; 0x1b; 0x78; 0x52; 0xb8; 0x55]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test2_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x38; 0xb0; 0x60; 0xa7; 0x51; 0xac; 0x96; 0x38; 0x4c; 0xd9; 0x32; 0x7e; 0xb1; 0xb1; 0xe3; 0x6a; 0x21; 0xfd; 0xb7; 0x11; 0x14; 0xbe; 0x07; 0x43; 0x4c; 0x0c; 0xc7; 0xbf; 0x63; 0xf6; 0xe1; 0xda; 0x27; 0x4e; 0xde; 0xbf; 0xe7; 0x6f; 0x65; 0xfb; 0xd5; 0x1a; 0xd2; 0xf1; 0x48; 0x98; 0xb9; 0x5b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test2_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x83; 0xe1; 0x35; 0x7e; 0xef; 0xb8; 0xbd; 0xf1; 0x54; 0x28; 0x50; 0xd6; 0x6d; 0x80; 0x07; 0xd6; 0x20; 0xe4; 0x05; 0x0b; 0x57; 0x15; 0xdc; 0x83; 0xf4; 0xa9; 0x21; 0xd3; 0x6c; 0xe9; 0xce; 0x47; 0xd0; 0xd1; 0x3c; 0x5d; 0x85; 0xf2; 0xb0; 0xff; 0x83; 0x18; 0xd2; 0x87; 0x7e; 0xec; 0x2f; 0x63; 0xb9; 0x31; 0xbd; 0x47; 0x41; 0x7a; 0x81; 0xa5; 0x38; 0x32; 0x7a; 0xf9; 0x27; 0xda; 0x3e]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test3_SHA2 // let test3_plaintext: b:lbuffer uint8 56ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x62; 0x63; 0x64; 0x65; 0x63; 0x64; 0x65; 0x66; 0x64; 0x65; 0x66; 0x67; 0x65; 0x66; 0x67; 0x68; 0x66; 0x67; 0x68; 0x69; 0x67; 0x68; 0x69; 0x6a; 0x68; 0x69; 0x6a; 0x6b; 0x69; 0x6a; 0x6b; 0x6c; 0x6a; 0x6b; 0x6c; 0x6d; 0x6b; 0x6c; 0x6d; 0x6e; 0x6c; 0x6d; 0x6e; 0x6f; 0x6d; 0x6e; 0x6f; 0x70; 0x6e; 0x6f; 0x70; 0x71]) in assert_norm (List.Tot.length l == 56); createL_mglobal l let test3_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x75; 0x38; 0x8b; 0x16; 0x51; 0x27; 0x76; 0xcc; 0x5d; 0xba; 0x5d; 0xa1; 0xfd; 0x89; 0x01; 0x50; 0xb0; 0xc6; 0x45; 0x5c; 0xb4; 0xf5; 0x8b; 0x19; 0x52; 0x52; 0x25; 0x25]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test3_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x24; 0x8d; 0x6a; 0x61; 0xd2; 0x06; 0x38; 0xb8; 0xe5; 0xc0; 0x26; 0x93; 0x0c; 0x3e; 0x60; 0x39; 0xa3; 0x3c; 0xe4; 0x59; 0x64; 0xff; 0x21; 0x67; 0xf6; 0xec; 0xed; 0xd4; 0x19; 0xdb; 0x06; 0xc1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test3_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x33; 0x91; 0xfd; 0xdd; 0xfc; 0x8d; 0xc7; 0x39; 0x37; 0x07; 0xa6; 0x5b; 0x1b; 0x47; 0x09; 0x39; 0x7c; 0xf8; 0xb1; 0xd1; 0x62; 0xaf; 0x05; 0xab; 0xfe; 0x8f; 0x45; 0x0d; 0xe5; 0xf3; 0x6b; 0xc6; 0xb0; 0x45; 0x5a; 0x85; 0x20; 0xbc; 0x4e; 0x6f; 0x5f; 0xe9; 0x5b; 0x1f; 0xe3; 0xc8; 0x45; 0x2b]) in assert_norm (List.Tot.length l == 48); createL_mglobal l let test3_expected_sha2_512: b:lbuffer uint8 64ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x20; 0x4a; 0x8f; 0xc6; 0xdd; 0xa8; 0x2f; 0x0a; 0x0c; 0xed; 0x7b; 0xeb; 0x8e; 0x08; 0xa4; 0x16; 0x57; 0xc1; 0x6e; 0xf4; 0x68; 0xb2; 0x28; 0xa8; 0x27; 0x9b; 0xe3; 0x31; 0xa7; 0x03; 0xc3; 0x35; 0x96; 0xfd; 0x15; 0xc1; 0x3b; 0x1b; 0x07; 0xf9; 0xaa; 0x1d; 0x3b; 0xea; 0x57; 0x78; 0x9c; 0xa0; 0x31; 0xad; 0x85; 0xc7; 0xa7; 0x1d; 0xd7; 0x03; 0x54; 0xec; 0x63; 0x12; 0x38; 0xca; 0x34; 0x45]) in assert_norm (List.Tot.length l == 64); createL_mglobal l // // Test4_SHA2 // let test4_plaintext: b:lbuffer uint8 112ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x61; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x62; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x63; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x64; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x65; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x66; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x67; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x68; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x69; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x6a; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x6b; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x6c; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x6d; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x6e; 0x6f; 0x70; 0x71; 0x72; 0x73; 0x74; 0x75]) in assert_norm (List.Tot.length l == 112); createL_mglobal l let test4_expected_sha2_224: b:lbuffer uint8 28ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xc9; 0x7c; 0xa9; 0xa5; 0x59; 0x85; 0x0c; 0xe9; 0x7a; 0x04; 0xa9; 0x6d; 0xef; 0x6d; 0x99; 0xa9; 0xe0; 0xe0; 0xe2; 0xab; 0x14; 0xe6; 0xb8; 0xdf; 0x26; 0x5f; 0xc0; 0xb3]) in assert_norm (List.Tot.length l == 28); createL_mglobal l let test4_expected_sha2_256: b:lbuffer uint8 32ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0xcf; 0x5b; 0x16; 0xa7; 0x78; 0xaf; 0x83; 0x80; 0x03; 0x6c; 0xe5; 0x9e; 0x7b; 0x04; 0x92; 0x37; 0x0b; 0x24; 0x9b; 0x11; 0xe8; 0xf0; 0x7a; 0x51; 0xaf; 0xac; 0x45; 0x03; 0x7a; 0xfe; 0xe9; 0xd1]) in assert_norm (List.Tot.length l == 32); createL_mglobal l let test4_expected_sha2_384: b:lbuffer uint8 48ul{ recallable b } = [@ inline_let] let l:list uint8 = normalize_term (List.Tot.map u8 [0x09; 0x33; 0x0c; 0x33; 0xf7; 0x11; 0x47; 0xe8; 0x3d; 0x19; 0x2f; 0xc7; 0x82; 0xcd; 0x1b; 0x47; 0x53; 0x11; 0x1b; 0x17; 0x3b; 0x3b; 0x05; 0xd2; 0x2f; 0xa0; 0x80; 0x86; 0xe3; 0xb0; 0xf7; 0x12; 0xfc; 0xc7; 0xc7; 0x1a; 0x55; 0x7e; 0x2d; 0xb9; 0x66; 0xc3; 0xe9; 0xfa; 0x91; 0x74; 0x60; 0x39]) in assert_norm (List.Tot.length l == 48); createL_mglobal l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (64ul <: FStar.UInt32.t) {Lib.Buffer.recallable b}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_mglobal", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.buffer", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.recallable", "Prims.list", "FStar.Pervasives.normalize_term", "FStar.List.Tot.Base.map", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Test.SHA2.u8", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
false
false
let test4_expected_sha2_512:b: lbuffer uint8 64ul {recallable b} =
[@@ inline_let ]let l:list uint8 = normalize_term (List.Tot.map u8 [ 0x8e; 0x95; 0x9b; 0x75; 0xda; 0xe3; 0x13; 0xda; 0x8c; 0xf4; 0xf7; 0x28; 0x14; 0xfc; 0x14; 0x3f; 0x8f; 0x77; 0x79; 0xc6; 0xeb; 0x9f; 0x7f; 0xa1; 0x72; 0x99; 0xae; 0xad; 0xb6; 0x88; 0x90; 0x18; 0x50; 0x1d; 0x28; 0x9e; 0x49; 0x00; 0xf7; 0xe4; 0x33; 0x1b; 0x99; 0xde; 0xc4; 0xb5; 0x43; 0x3a; 0xc7; 0xd3; 0x29; 0xee; 0xb6; 0xdd; 0x26; 0x54; 0x5e; 0x96; 0xe5; 0x5b; 0x87; 0x4b; 0xe9; 0x09 ]) in assert_norm (List.Tot.length l == 64); createL_mglobal l
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.return_lpre
val return_lpre (#st: st) (#a: Type) (#post: post_t st a) (x: a) (lpost: l_post (post x) post) : l_pre (post x)
val return_lpre (#st: st) (#a: Type) (#post: post_t st a) (x: a) (lpost: l_post (post x) post) : l_pre (post x)
let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 22, "end_line": 354, "start_col": 0, "start_line": 351 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> lpost: Steel.Semantics.Hoare.MST.l_post (post x) post -> Steel.Semantics.Hoare.MST.l_pre (post x)
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.l_pre" ]
[]
false
false
false
false
false
let return_lpre (#st: st) (#a: Type) (#post: post_t st a) (x: a) (lpost: l_post (post x) post) : l_pre (post x) =
fun h -> lpost h x h
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.bind_lpre
val bind_lpre (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (lpre_b: (x: a -> l_pre (post_a x))) : l_pre pre
val bind_lpre (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (lpre_b: (x: a -> l_pre (post_a x))) : l_pre pre
let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 72, "end_line": 386, "start_col": 0, "start_line": 376 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpre_a: Steel.Semantics.Hoare.MST.l_pre pre -> lpost_a: Steel.Semantics.Hoare.MST.l_post pre post_a -> lpre_b: (x: a -> Steel.Semantics.Hoare.MST.l_pre (post_a x)) -> Steel.Semantics.Hoare.MST.l_pre pre
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.l_Forall", "Prims.l_imp", "Prims.prop" ]
[]
false
false
false
false
false
let bind_lpre (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (lpre_b: (x: a -> l_pre (post_a x))) : l_pre pre =
fun h -> lpre_a h /\ (forall (x: a) h1. lpost_a h x h1 ==> lpre_b x h1)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.par_lpre
val par_lpre (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#preR: st.hprop) (lpreR: l_pre preR) : l_pre (preL `st.star` preR)
val par_lpre (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#preR: st.hprop) (lpreR: l_pre preR) : l_pre (preL `st.star` preR)
let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 29, "end_line": 412, "start_col": 0, "start_line": 404 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> Steel.Semantics.Hoare.MST.l_pre (Mkst0?.star st preL preR)
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
false
false
false
false
false
let par_lpre (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#preR: st.hprop) (lpreR: l_pre preR) : l_pre (preL `st.star` preR) =
fun h -> lpreL h /\ lpreR h
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.frame_lpre
val frame_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#frame: st.hprop) (f_frame: fp_prop frame) : l_pre (pre `st.star` frame)
val frame_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#frame: st.hprop) (f_frame: fp_prop frame) : l_pre (pre `st.star` frame)
let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 359, "start_col": 0, "start_line": 356 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> f_frame: Steel.Semantics.Hoare.MST.fp_prop frame -> Steel.Semantics.Hoare.MST.l_pre (Mkst0?.star st pre frame)
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.fp_prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
false
false
false
false
false
let frame_lpre (#st: st) (#pre: st.hprop) (lpre: l_pre pre) (#frame: st.hprop) (f_frame: fp_prop frame) : l_pre (pre `st.star` frame) =
fun h -> lpre h /\ f_frame h
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.bind_lpost
val bind_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (#b: Type) (#post_b: post_t st b) (lpost_b: (x: a -> l_post (post_a x) post_b)) : l_post pre post_b
val bind_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (#b: Type) (#post_b: post_t st b) (lpost_b: (x: a -> l_post (post_a x) post_b)) : l_post pre post_b
let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 83, "end_line": 400, "start_col": 0, "start_line": 388 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpre_a: Steel.Semantics.Hoare.MST.l_pre pre -> lpost_a: Steel.Semantics.Hoare.MST.l_post pre post_a -> lpost_b: (x: a -> Steel.Semantics.Hoare.MST.l_post (post_a x) post_b) -> Steel.Semantics.Hoare.MST.l_post pre post_b
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.l_Exists", "Prims.prop" ]
[]
false
false
false
false
false
let bind_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post_a: post_t st a) (lpre_a: l_pre pre) (lpost_a: l_post pre post_a) (#b: Type) (#post_b: post_t st b) (lpost_b: (x: a -> l_post (post_a x) post_b)) : l_post pre post_b =
fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.par_lpost
val par_lpost (#st: st) (#aL: Type) (#preL: st.hprop) (#postL: post_t st aL) (lpreL: l_pre preL) (lpostL: l_post preL postL) (#aR: Type) (#preR: st.hprop) (#postR: post_t st aR) (lpreR: l_pre preR) (lpostR: l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> (postL xL) `st.star` (postR xR))
val par_lpost (#st: st) (#aL: Type) (#preL: st.hprop) (#postL: post_t st aL) (lpreL: l_pre preL) (lpostL: l_post preL postL) (#aR: Type) (#preR: st.hprop) (#postR: post_t st aR) (lpreR: l_pre preR) (lpostR: l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> (postL xL) `st.star` (postR xR))
let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 82, "end_line": 428, "start_col": 0, "start_line": 414 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpostL: Steel.Semantics.Hoare.MST.l_post preL postL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> lpostR: Steel.Semantics.Hoare.MST.l_post preR postR -> Steel.Semantics.Hoare.MST.l_post (Mkst0?.star st preL preR) (fun _ -> (let FStar.Pervasives.Native.Mktuple2 #_ #_ xL xR = _ in Mkst0?.star st (postL xL) (postR xR)) <: Mkst0?.hprop st)
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
false
false
false
false
false
let par_lpost (#st: st) (#aL: Type) (#preL: st.hprop) (#postL: post_t st aL) (lpreL: l_pre preL) (lpostL: l_post preL postL) (#aR: Type) (#preR: st.hprop) (#postR: post_t st aR) (lpreR: l_pre preR) (lpostR: l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> (postL xL) `st.star` (postR xR)) =
fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.frame_lpost
val frame_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#frame: st.hprop) (f_frame: fp_prop frame) : l_post (pre `st.star` frame) (fun x -> (post x) `st.star` frame)
val frame_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#frame: st.hprop) (f_frame: fp_prop frame) : l_post (pre `st.star` frame) (fun x -> (post x) `st.star` frame)
let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 372, "start_col": 0, "start_line": 361 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpre: Steel.Semantics.Hoare.MST.l_pre pre -> lpost: Steel.Semantics.Hoare.MST.l_post pre post -> f_frame: Steel.Semantics.Hoare.MST.fp_prop frame -> Steel.Semantics.Hoare.MST.l_post (Mkst0?.star st pre frame) (fun x -> Mkst0?.star st (post x) frame)
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.fp_prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_and", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star" ]
[]
false
false
false
false
false
let frame_lpost (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpre: l_pre pre) (lpost: l_post pre post) (#frame: st.hprop) (f_frame: fp_prop frame) : l_post (pre `st.star` frame) (fun x -> (post x) `st.star` frame) =
fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1
false
Hacl.Test.SHA2.fst
Hacl.Test.SHA2.test_sha2
val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True)
val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True)
let test_sha2 msg_len msg expected224 expected256 expected384 expected512 = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame(); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame()
{ "file_name": "code/tests/Hacl.Test.SHA2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 44, "start_col": 0, "start_line": 27 }
module Hacl.Test.SHA2 open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.PrintBuffer open Hacl.Streaming.SHA2 open Hacl.Hash.SHA2 #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val test_sha2: msg_len:size_t -> msg:lbuffer uint8 msg_len -> expected224:lbuffer uint8 28ul -> expected256:lbuffer uint8 32ul -> expected384:lbuffer uint8 48ul -> expected512:lbuffer uint8 64ul -> Stack unit (requires fun h -> live h msg /\ live h expected224 /\ live h expected256 /\ live h expected384 /\ live h expected512) (ensures fun h0 r h1 -> True)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.PrintBuffer.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Hash.SHA2.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.All.fst.checked", "C.String.fsti.checked", "C.fst.checked" ], "interface_file": false, "source_file": "Hacl.Test.SHA2.fst" }
[ { "abbrev": false, "full_module": "Hacl.Hash.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Lib.PrintBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Test", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> expected224: Lib.Buffer.lbuffer Lib.IntTypes.uint8 28ul -> expected256: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> expected384: Lib.Buffer.lbuffer Lib.IntTypes.uint8 48ul -> expected512: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "C.exit", "FStar.Int32.__int_to_t", "Prims.bool", "Prims.op_Negation", "Lib.PrintBuffer.result_compare_display", "Lib.Buffer.to_const", "Lib.Buffer.MUT", "Hacl.Streaming.SHA2.hash_512", "Hacl.Streaming.SHA2.hash_384", "Hacl.Streaming.SHA2.hash_256", "Hacl.Streaming.SHA2.hash_224", "Lib.Buffer.lbuffer_t", "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", "FStar.Math.Lemmas.pow2_lt_compat" ]
[]
false
true
false
false
false
let test_sha2 msg_len msg expected224 expected256 expected384 expected512 =
Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32; push_frame (); let test224 = create 28ul (u8 0) in let test256 = create 32ul (u8 0) in let test384 = create 48ul (u8 0) in let test512 = create 64ul (u8 0) in hash_224 (test224 <: lbuffer uint8 28ul) msg msg_len; hash_256 (test256 <: lbuffer uint8 32ul) msg msg_len; hash_384 (test384 <: lbuffer uint8 48ul) msg msg_len; hash_512 (test512 <: lbuffer uint8 64ul) msg msg_len; if not (result_compare_display 28ul (to_const test224) (to_const expected224)) then C.exit 255l; if not (result_compare_display 32ul (to_const test256) (to_const expected256)) then C.exit 255l; if not (result_compare_display 48ul (to_const test384) (to_const expected384)) then C.exit 255l; if not (result_compare_display 64ul (to_const test512) (to_const expected512)) then C.exit 255l; pop_frame ()
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.assoc_star_right
val assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s))))
val assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s))))
let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); }
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 708, "start_col": 0, "start_line": 698 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> FStar.Pervasives.Lemma (ensures Mkst0?.equals st (Mkst0?.star st p (Mkst0?.star st (Mkst0?.star st q r) s)) (Mkst0?.star st p (Mkst0?.star st q (Mkst0?.star st r s))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.squash", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) =
calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); }
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.commute_assoc_star_right
val commute_assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s))))
val commute_assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s))))
let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); }
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 723, "start_col": 0, "start_line": 710 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> FStar.Pervasives.Lemma (ensures Mkst0?.equals st (Mkst0?.star st p (Mkst0?.star st (Mkst0?.star st q r) s)) (Mkst0?.star st p (Mkst0?.star st r (Mkst0?.star st q s))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.squash", "Steel.Semantics.Hoare.MST.assoc_star_right", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let commute_assoc_star_right (#st: st) (p q r s: st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) =
calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); }
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.commute_star_right
val commute_star_right (#st: st) (p q r: st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q)))
val commute_star_right (#st: st) (p q r: st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q)))
let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); }
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 696, "start_col": 0, "start_line": 687 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> FStar.Pervasives.Lemma (ensures Mkst0?.equals st (Mkst0?.star st p (Mkst0?.star st q r)) (Mkst0?.star st p (Mkst0?.star st r q)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.squash", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let commute_star_right (#st: st) (p q r: st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) =
calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); }
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.equals_ext_right
val equals_ext_right (#st: st) (p q r: st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r))
val equals_ext_right (#st: st) (p q r: st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r))
let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; }
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 685, "start_col": 0, "start_line": 672 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> FStar.Pervasives.Lemma (requires Mkst0?.equals st q r) (ensures Mkst0?.equals st (Mkst0?.star st p q) (Mkst0?.star st p r))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let equals_ext_right (#st: st) (p q r: st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) =
calc (st.equals) { p `st.star` q; (st.equals) { () } q `st.star` p; (st.equals) { () } r `st.star` p; (st.equals) { () } p `st.star` r; }
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.commute_star_par_l
val commute_star_par_l (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((p `st.star` (q `st.star` r)) `st.star` s) m0)
val commute_star_par_l (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((p `st.star` (q `st.star` r)) `st.star` s) m0)
let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s))
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 54, "end_line": 730, "start_col": 0, "start_line": 725 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> m0: Mkst0?.mem st -> FStar.Pervasives.Lemma (ensures Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st p q) r) s) m0 <==> Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st p (Mkst0?.star st q r)) s) m0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims._assert", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let commute_star_par_l (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((p `st.star` (q `st.star` r)) `st.star` s) m0) =
assert ((((p `st.star` q) `st.star` r) `st.star` s) `st.equals` ((p `st.star` (q `st.star` r)) `st.star` s))
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.inst_heap_prop_for_par
val inst_heap_prop_for_par (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (state: st.mem) : fp_prop pre
val inst_heap_prop_for_par (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (state: st.mem) : fp_prop pre
let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 819, "start_col": 0, "start_line": 807 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpost: Steel.Semantics.Hoare.MST.l_post pre post -> state: Mkst0?.mem st -> Steel.Semantics.Hoare.MST.fp_prop pre
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.l_Forall", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.prop", "Steel.Semantics.Hoare.MST.fp_prop" ]
[]
false
false
false
false
false
let inst_heap_prop_for_par (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (state: st.mem) : fp_prop pre =
fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.commute_star_par_r
val commute_star_par_r (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((q `st.star` (p `st.star` r)) `st.star` s) m0)
val commute_star_par_r (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((q `st.star` (p `st.star` r)) `st.star` s) m0)
let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; }
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 742, "start_col": 0, "start_line": 732 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Mkst0?.hprop st -> q: Mkst0?.hprop st -> r: Mkst0?.hprop st -> s: Mkst0?.hprop st -> m0: Mkst0?.mem st -> FStar.Pervasives.Lemma (ensures Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st p q) r) s) m0 <==> Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st q (Mkst0?.star st p r)) s) m0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Prims.l_True", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let commute_star_par_r (#st: st) (p q r s: st.hprop) (m0: st.mem) : Lemma (st.interp (((p `st.star` q) `st.star` r) `st.star` s) m0 <==> st.interp ((q `st.star` (p `st.star` r)) `st.star` s) m0) =
calc (st.equals) { ((p `st.star` q) `st.star` r) `st.star` s; (st.equals) { () } ((q `st.star` p) `st.star` r) `st.star` s; (st.equals) { () } (q `st.star` (p `st.star` r)) `st.star` s; }
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.depends_only_on_commutes_with_weaker
val depends_only_on_commutes_with_weaker (#st: st) (q: (st.mem -> prop)) (fp fp_next: st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next)
val depends_only_on_commutes_with_weaker (#st: st) (q: (st.mem -> prop)) (fp fp_next: st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next)
let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 91, "end_line": 774, "start_col": 0, "start_line": 765 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: (_: Mkst0?.mem st -> Prims.prop) -> fp: Mkst0?.hprop st -> fp_next: Mkst0?.hprop st -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.depends_only_on q fp /\ Steel.Semantics.Hoare.MST.weaker_pre fp_next fp) (ensures Steel.Semantics.Hoare.MST.depends_only_on q fp_next)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims._assert", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_heap_0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__emp", "Prims.unit", "Prims.l_and", "Steel.Semantics.Hoare.MST.depends_only_on", "Steel.Semantics.Hoare.MST.weaker_pre", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let depends_only_on_commutes_with_weaker (#st: st) (q: (st.mem -> prop)) (fp fp_next: st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) =
assert (forall (h0: fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.depends_only_on2_commutes_with_weaker
val depends_only_on2_commutes_with_weaker (#st: st) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp fp_next: st.hprop) (fp_post: (a -> st.hprop)) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post)
val depends_only_on2_commutes_with_weaker (#st: st) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp fp_next: st.hprop) (fp_post: (a -> st.hprop)) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post)
let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 91, "end_line": 787, "start_col": 0, "start_line": 776 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: (_: Mkst0?.mem st -> _: a -> _: Mkst0?.mem st -> Prims.prop) -> fp: Mkst0?.hprop st -> fp_next: Mkst0?.hprop st -> fp_post: (_: a -> Mkst0?.hprop st) -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.depends_only_on2 q fp fp_post /\ Steel.Semantics.Hoare.MST.weaker_pre fp_next fp) (ensures Steel.Semantics.Hoare.MST.depends_only_on2 q fp_next fp_post)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Prims._assert", "Prims.l_Forall", "Steel.Semantics.Hoare.MST.fp_heap_0", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__emp", "Prims.unit", "Prims.l_and", "Steel.Semantics.Hoare.MST.depends_only_on2", "Steel.Semantics.Hoare.MST.weaker_pre", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let depends_only_on2_commutes_with_weaker (#st: st) (#a: Type) (q: (st.mem -> a -> st.mem -> prop)) (fp fp_next: st.hprop) (fp_post: (a -> st.hprop)) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) =
assert (forall (h0: fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.frame_post_for_par
val frame_post_for_par (#st: st) (pre_s post_s: st.hprop) (m0 m1: st.mem) (#a: Type) (#pre_f: st.hprop) (#post_f: post_t st a) (lpre_f: l_pre pre_f) (lpost_f: l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` (st.locks_invariant m0)) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x: a) (final_state: st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state))
val frame_post_for_par (#st: st) (pre_s post_s: st.hprop) (m0 m1: st.mem) (#a: Type) (#pre_f: st.hprop) (#post_f: post_t st a) (lpre_f: l_pre pre_f) (lpost_f: l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` (st.locks_invariant m0)) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x: a) (final_state: st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state))
let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 51, "end_line": 866, "start_col": 0, "start_line": 846 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pre_s: Mkst0?.hprop st -> post_s: Mkst0?.hprop st -> m0: Mkst0?.mem st -> m1: Mkst0?.mem st -> lpre_f: Steel.Semantics.Hoare.MST.l_pre pre_f -> lpost_f: Steel.Semantics.Hoare.MST.l_post pre_f post_f -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.post_preserves_frame post_s pre_f m0 m1 /\ Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st pre_s pre_f) (Mkst0?.locks_invariant st m0)) m0) (ensures (lpre_f (Mkst0?.core st m0) <==> lpre_f (Mkst0?.core st m1)) /\ (forall (x: a) (final_state: Mkst0?.mem st). lpost_f (Mkst0?.core st m0) x final_state <==> lpost_f (Mkst0?.core st m1) x final_state ))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.frame_post_for_par_aux", "Prims.unit", "Steel.Semantics.Hoare.MST.frame_post_for_par_tautology", "Prims.l_and", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.squash", "Prims.l_iff", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.l_Forall", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let frame_post_for_par (#st: st) (pre_s post_s: st.hprop) (m0 m1: st.mem) (#a: Type) (#pre_f: st.hprop) (#post_f: post_t st a) (lpre_f: l_pre pre_f) (lpost_f: l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` (st.locks_invariant m0)) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x: a) (final_state: st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) =
frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_bind_ret
val step_bind_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
val step_bind_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 63, "end_line": 1086, "start_col": 0, "start_line": 1075 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)} -> Steel.Semantics.Hoare.MST.Mst (Steel.Semantics.Hoare.MST.step_result st a)
Steel.Semantics.Hoare.MST.Mst
[]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Bind", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Bind__item__a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__pre", "Steel.Semantics.Hoare.MST.__proj__Bind__item__post_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpre_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpost_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__f", "FStar.Pervasives.Native.tuple2", "FStar.NMST.tape", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.step_bind_ret_aux", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
false
true
false
false
false
let step_bind_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) =
NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n)
false
Vale.AES.AES_helpers.fsti
Vale.AES.AES_helpers.quad32_shl32
val quad32_shl32 (q: quad32) : quad32
val quad32_shl32 (q: quad32) : quad32
let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 19, "start_col": 0, "start_line": 17 }
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour" ]
[]
false
false
false
true
false
let quad32_shl32 (q: quad32) : quad32 =
let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2
false
Vale.AES.AES_helpers.fsti
Vale.AES.AES_helpers.expand_key_128
val expand_key_128 : key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> round: Prims.nat -> Prims.Pure Vale.Def.Types_s.quad32
let expand_key_128 = opaque_make expand_key_128_def
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 70, "end_line": 42, "start_col": 19, "start_line": 42 }
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3 let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1)) let rec expand_key_128_def (key:seq nat32) (round:nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) = if round = 0 then Mkfour key.[0] key.[1] key.[2] key.[3]
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> round: Prims.nat -> Prims.Pure Vale.Def.Types_s.quad32
Prims.Pure
[]
[]
[ "Vale.Def.Opaque_s.opaque_make", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Prims.nat", "Vale.Def.Types_s.quad32", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.AES_common_s.AES_128", "Prims.l_True", "Vale.AES.AES_helpers.expand_key_128_def" ]
[]
false
false
false
false
false
let expand_key_128 =
opaque_make expand_key_128_def
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.par_weaker_lpre_and_stronger_lpost_l
val par_weaker_lpre_and_stronger_lpost_l (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#next_preL: st.hprop) (#next_postL: post_t st aL) (next_lpreL: l_pre next_preL) (next_lpostL: l_post next_preL next_postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` (st.locks_invariant state)) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state)
val par_weaker_lpre_and_stronger_lpost_l (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#next_preL: st.hprop) (#next_postL: post_t st aL) (next_lpreL: l_pre next_preL) (next_lpostL: l_post next_preL next_postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` (st.locks_invariant state)) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state)
let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ])
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 52, "end_line": 908, "start_col": 0, "start_line": 871 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpostL: Steel.Semantics.Hoare.MST.l_post preL postL -> next_lpreL: Steel.Semantics.Hoare.MST.l_pre next_preL -> next_lpostL: Steel.Semantics.Hoare.MST.l_post next_preL next_postL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> lpostR: Steel.Semantics.Hoare.MST.l_post preR postR -> state: Mkst0?.mem st -> next_state: Mkst0?.mem st -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.weaker_lpre lpreL next_lpreL state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost lpostL next_lpostL state next_state /\ Steel.Semantics.Hoare.MST.post_preserves_frame next_preL preR state next_state /\ lpreL (Mkst0?.core st state) /\ lpreR (Mkst0?.core st state) /\ Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st preL preR) (Mkst0?.locks_invariant st state)) state) (ensures Steel.Semantics.Hoare.MST.weaker_lpre (Steel.Semantics.Hoare.MST.par_lpre lpreL lpreR) (Steel.Semantics.Hoare.MST.par_lpre next_lpreL lpreR) state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost (Steel.Semantics.Hoare.MST.par_lpost lpreL lpostL lpreR lpostR) (Steel.Semantics.Hoare.MST.par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "FStar.Tactics.Effect.assert_by_tactic", "Steel.Semantics.Hoare.MST.weaker_lpre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.par_lpre", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "Steel.Semantics.Hoare.MST.frame_post_for_par", "Prims.l_and", "Steel.Semantics.Hoare.MST.stronger_lpost", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.squash", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.par_lpost", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let par_weaker_lpre_and_stronger_lpost_l (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#next_preL: st.hprop) (#next_postL: post_t st aL) (next_lpreL: l_pre next_preL) (next_lpostL: l_post next_preL next_postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` (st.locks_invariant state)) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) =
frame_post_for_par preL next_preL state next_state lpreR lpostR; FStar.Tactics.Effect.assert_by_tactic (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) (fun _ -> (); (norm [delta_only [`%weaker_lpre; `%par_lpre]]))
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.lpost_ret_act
val lpost_ret_act (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (x: a) (state: st.mem) : l_post (post x) post
val lpost_ret_act (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (x: a) (state: st.mem) : l_post (post x) post
let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 1034, "start_col": 0, "start_line": 1024 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpost: Steel.Semantics.Hoare.MST.l_post pre post -> x: a -> state: Mkst0?.mem st -> Steel.Semantics.Hoare.MST.l_post (post x) post
Prims.Tot
[ "total" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "Prims.prop" ]
[]
false
false
false
false
false
let lpost_ret_act (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (lpost: l_post pre post) (x: a) (state: st.mem) : l_post (post x) post =
fun _ x h1 -> lpost (st.core state) x h1
false
Vale.AES.AES_helpers.fsti
Vale.AES.AES_helpers.round_key_128
val round_key_128 (prev: quad32) (round: nat) : quad32
val round_key_128 (prev: quad32) (round: nat) : quad32
let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1))
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 34, "start_col": 0, "start_line": 33 }
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
prev: Vale.Def.Types_s.quad32 -> round: Prims.nat -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.AES.AES_helpers.round_key_128_rcon", "Vale.AES.AES_common_s.aes_rcon", "Prims.op_Subtraction" ]
[]
false
false
false
true
false
let round_key_128 (prev: quad32) (round: nat) : quad32 =
round_key_128_rcon prev (aes_rcon (round - 1))
false
Vale.AES.AES_helpers.fsti
Vale.AES.AES_helpers.expand_key_128_reveal
val expand_key_128_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.AES_helpers.expand_key_128 == Vale.AES.AES_helpers.expand_key_128_def)
let expand_key_128_reveal = opaque_revealer (`%expand_key_128) expand_key_128 expand_key_128_def
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 108, "end_line": 43, "start_col": 12, "start_line": 43 }
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3 let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1)) let rec expand_key_128_def (key:seq nat32) (round:nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) = if round = 0 then Mkfour key.[0] key.[1] key.[2] key.[3] else round_key_128 (expand_key_128_def key (round - 1)) round
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.AES_helpers.expand_key_128 == Vale.AES.AES_helpers.expand_key_128_def)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Opaque_s.opaque_revealer", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Prims.nat", "Vale.Def.Types_s.quad32", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.AES_common_s.AES_128", "Prims.l_True", "Vale.AES.AES_helpers.expand_key_128", "Vale.AES.AES_helpers.expand_key_128_def" ]
[]
true
false
true
false
false
let expand_key_128_reveal =
opaque_revealer (`%expand_key_128) expand_key_128 expand_key_128_def
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.stronger_post_par_r
val stronger_post_par_r (#st: st) (#aL #aR: Type u#a) (postL: post_t st aL) (postR next_postR: post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h ==> st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h)
val stronger_post_par_r (#st: st) (#aL #aR: Type u#a) (postL: post_t st aL) (postR next_postR: post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h ==> st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h)
let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in ()
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 1003, "start_col": 0, "start_line": 967 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
postL: Steel.Semantics.Hoare.MST.post_t st aL -> postR: Steel.Semantics.Hoare.MST.post_t st aR -> next_postR: Steel.Semantics.Hoare.MST.post_t st aR -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.stronger_post postR next_postR) (ensures forall (xL: aL) (xR: aR) (frame: Mkst0?.hprop st) (h: Mkst0?.mem st). Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (postL xL) (next_postR xR)) frame) h ==> Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (postL xL) (postR xR)) frame) h)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.unit", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims._assert", "Steel.Semantics.Hoare.MST.stronger_post", "Prims.l_Forall", "Prims.l_imp" ]
[]
false
false
true
false
false
let stronger_post_par_r (#st: st) (#aL #aR: Type u#a) (postL: post_t st aL) (postR next_postR: post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h ==> st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h) =
let aux xL xR frame h : Lemma (requires st.interp (((postL xL) `st.star` (next_postR xR)) `st.star` frame) h) (ensures st.interp (((postL xL) `st.star` (postR xR)) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { ((postL xL) `st.star` (next_postR xR)) `st.star` frame; (st.equals) { () } ((next_postR xR) `st.star` (postL xL)) `st.star` frame; (st.equals) { () } (next_postR xR) `st.star` ((postL xL) `st.star` frame); }; assert (st.interp ((next_postR xR) `st.star` ((postL xL) `st.star` frame)) h); assert (st.interp ((postR xR) `st.star` ((postL xL) `st.star` frame)) h); calc (st.equals) { (postR xR) `st.star` ((postL xL) `st.star` frame); (st.equals) { () } ((postR xR) `st.star` (postL xL)) `st.star` frame; (st.equals) { () } ((postL xL) `st.star` (postR xR)) `st.star` frame; } in ()
false
Vale.AES.AES_helpers.fsti
Vale.AES.AES_helpers.round_key_128_rcon
val round_key_128_rcon (prev: quad32) (rcon: nat32) : quad32
val round_key_128_rcon (prev: quad32) (rcon: nat32) : quad32
let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 20, "end_line": 31, "start_col": 0, "start_line": 25 }
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent.
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
prev: Vale.Def.Types_s.quad32 -> rcon: Vale.Def.Types_s.nat32 -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Words_s.nat32", "Vale.AES.AES_helpers.op_Star_Hat", "Vale.AES.AES_common_s.sub_word", "Vale.AES.AES_s.rot_word_LE" ]
[]
false
false
false
true
false
let round_key_128_rcon (prev: quad32) (rcon: nat32) : quad32 =
let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3
false
Vale.AES.AES_helpers.fsti
Vale.AES.AES_helpers.simd_round_key_128
val simd_round_key_128 (prev: quad32) (rcon: nat32) : quad32
val simd_round_key_128 (prev: quad32) (rcon: nat32) : quad32
let simd_round_key_128 (prev:quad32) (rcon:nat32) : quad32 = let r = rot_word_LE (sub_word prev.hi3) *^ rcon in let q = prev in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in q *^^ Mkfour r r r r
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 83, "start_col": 0, "start_line": 77 }
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3 let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1)) let rec expand_key_128_def (key:seq nat32) (round:nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) = if round = 0 then Mkfour key.[0] key.[1] key.[2] key.[3] else round_key_128 (expand_key_128_def key (round - 1)) round [@"opaque_to_smt"] let expand_key_128 = opaque_make expand_key_128_def irreducible let expand_key_128_reveal = opaque_revealer (`%expand_key_128) expand_key_128 expand_key_128_def val lemma_expand_key_128_0 (key:aes_key_LE AES_128) : Lemma (equal key (expand_key AES_128 key 4)) val lemma_expand_key_128_i (key:aes_key_LE AES_128) (i:nat) : Lemma (requires 0 < i /\ i < 11 ) (ensures ( let m = 4 * (i - 1) in let n = 4 * i in let v = expand_key AES_128 key n in let w = expand_key AES_128 key (n + 4) in let prev = Mkfour v.[m + 0] v.[m + 1] v.[m + 2] v.[m + 3] in round_key_128 prev i == Mkfour w.[n + 0] w.[n + 1] w.[n + 2] w.[n + 3] )) // expand_key for large 'size' argument agrees with expand_key for smaller 'size' argument val lemma_expand_append (key:aes_key_LE AES_128) (size1:nat) (size2:nat) : Lemma (requires size1 <= size2 /\ size2 <= 44) (ensures equal (expand_key AES_128 key size1) (slice (expand_key AES_128 key size2) 0 size1)) (decreases size2) // quad32 key expansion is equivalent to nat32 key expansion val lemma_expand_key_128 (key:seq nat32) (size:nat) : Lemma (requires size <= 11 /\ is_aes_key_LE AES_128 key) (ensures ( let s = key_schedule_to_round_keys size (expand_key AES_128 key 44) in (forall (i:nat).{:pattern (expand_key_128 key i) \/ (expand_key_128_def key i)} i < size ==> expand_key_128 key i == s.[i]) ))
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
prev: Vale.Def.Types_s.quad32 -> rcon: Vale.Def.Types_s.nat32 -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.AES.AES_helpers.op_Star_Hat_Hat", "Vale.Def.Words_s.Mkfour", "Vale.AES.AES_helpers.quad32_shl32", "Vale.Def.Words_s.nat32", "Vale.AES.AES_helpers.op_Star_Hat", "Vale.AES.AES_s.rot_word_LE", "Vale.AES.AES_common_s.sub_word", "Vale.Def.Words_s.__proj__Mkfour__item__hi3" ]
[]
false
false
false
true
false
let simd_round_key_128 (prev: quad32) (rcon: nat32) : quad32 =
let r = rot_word_LE (sub_word prev.hi3) *^ rcon in let q = prev in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in let q = q *^^ quad32_shl32 q in q *^^ Mkfour r r r r
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_frame_ret
val step_frame_ret (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
val step_frame_ret (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 64, "end_line": 1164, "start_col": 0, "start_line": 1153 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)} -> Steel.Semantics.Hoare.MST.Mst (Steel.Semantics.Hoare.MST.step_result st a)
Steel.Semantics.Hoare.MST.Mst
[]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Frame", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Frame__item__a", "Steel.Semantics.Hoare.MST.__proj__Frame__item__pre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__post", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpost", "Steel.Semantics.Hoare.MST.__proj__Frame__item__f", "FStar.Pervasives.Native.tuple2", "FStar.NMST.tape", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.step_frame_ret_aux", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
false
true
false
false
false
let step_frame_ret (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) =
NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_bind_ret_aux
val step_bind_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
val step_bind_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 57, "end_line": 1073, "start_col": 0, "start_line": 1059 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)} -> FStar.MST.MSTATE (Steel.Semantics.Hoare.MST.step_result st a)
FStar.MST.MSTATE
[]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Bind", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Bind__item__a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__pre", "Steel.Semantics.Hoare.MST.__proj__Bind__item__post_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpre_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__lpost_a", "Steel.Semantics.Hoare.MST.__proj__Bind__item__f", "Steel.Semantics.Hoare.MST.full_mem", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.Step", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
false
true
false
false
false
let step_bind_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) =
M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.par_weaker_lpre_and_stronger_lpost_r
val par_weaker_lpre_and_stronger_lpost_r (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (#next_preR: st.hprop) (#next_postR: post_t st aR) (next_lpreR: l_pre next_preR) (next_lpostR: l_post next_preR next_postR) (frame: st.hprop) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp (((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state)) state) (ensures st.interp (((preL `st.star` next_preR) `st.star` frame) `st.star` (st.locks_invariant next_state)) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state)
val par_weaker_lpre_and_stronger_lpost_r (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (#next_preR: st.hprop) (#next_postR: post_t st aR) (next_lpreR: l_pre next_preR) (next_lpostR: l_post next_preR next_postR) (frame: st.hprop) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp (((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state)) state) (ensures st.interp (((preL `st.star` next_preR) `st.star` frame) `st.star` (st.locks_invariant next_state)) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state)
let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 84, "end_line": 964, "start_col": 0, "start_line": 910 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ])
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lpreL: Steel.Semantics.Hoare.MST.l_pre preL -> lpostL: Steel.Semantics.Hoare.MST.l_post preL postL -> lpreR: Steel.Semantics.Hoare.MST.l_pre preR -> lpostR: Steel.Semantics.Hoare.MST.l_post preR postR -> next_lpreR: Steel.Semantics.Hoare.MST.l_pre next_preR -> next_lpostR: Steel.Semantics.Hoare.MST.l_post next_preR next_postR -> frame: Mkst0?.hprop st -> state: Mkst0?.mem st -> next_state: Mkst0?.mem st -> FStar.Pervasives.Lemma (requires Steel.Semantics.Hoare.MST.weaker_lpre lpreR next_lpreR state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost lpostR next_lpostR state next_state /\ Steel.Semantics.Hoare.MST.post_preserves_frame next_preR (Mkst0?.star st preL frame) state next_state /\ lpreR (Mkst0?.core st state) /\ lpreL (Mkst0?.core st state) /\ Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st preL preR) frame) (Mkst0?.locks_invariant st state)) state) (ensures Mkst0?.interp st (Mkst0?.star st (Mkst0?.star st (Mkst0?.star st preL next_preR) frame) (Mkst0?.locks_invariant st next_state)) next_state /\ Steel.Semantics.Hoare.MST.weaker_lpre (Steel.Semantics.Hoare.MST.par_lpre lpreL lpreR) (Steel.Semantics.Hoare.MST.par_lpre lpreL next_lpreR) state next_state /\ Steel.Semantics.Hoare.MST.stronger_lpost (Steel.Semantics.Hoare.MST.par_lpost lpreL lpostL lpreR lpostR) (Steel.Semantics.Hoare.MST.par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Hoare.MST.commute_star_par_r", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Steel.Semantics.Hoare.MST.weaker_lpre", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.par_lpre", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "Steel.Semantics.Hoare.MST.frame_post_for_par", "Prims._assert", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp", "FStar.Calc.calc_finish", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__equals", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Steel.Semantics.Hoare.MST.equals_ext_right", "Prims.l_and", "Steel.Semantics.Hoare.MST.stronger_lpost", "Steel.Semantics.Hoare.MST.post_preserves_frame", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__core", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.par_lpost", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let par_weaker_lpre_and_stronger_lpost_r (#st: st) (#preL: st.hprop) (lpreL: l_pre preL) (#aL: Type) (#postL: post_t st aL) (lpostL: l_post preL postL) (#preR: st.hprop) (lpreR: l_pre preR) (#aR: Type) (#postR: post_t st aR) (lpostR: l_post preR postR) (#next_preR: st.hprop) (#next_postR: post_t st aR) (next_lpreR: l_pre next_preR) (next_lpostR: l_post next_preR next_postR) (frame: st.hprop) (state next_state: st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp (((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state)) state) (ensures st.interp (((preL `st.star` next_preR) `st.star` frame) `st.star` (st.locks_invariant next_state)) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) =
calc (st.equals) { ((preL `st.star` preR) `st.star` frame) `st.star` (st.locks_invariant state); (st.equals) { () } ((preR `st.star` preL) `st.star` frame) `st.star` (st.locks_invariant state); (st.equals) { () } (preR `st.star` preL) `st.star` (frame `st.star` (st.locks_invariant state)); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` (st.locks_invariant state)) ((st.locks_invariant state) `st.star` frame) } (preR `st.star` preL) `st.star` ((st.locks_invariant state) `st.star` frame); (st.equals) { () } ((preR `st.star` preL) `st.star` (st.locks_invariant state)) `st.star` frame; }; assert (st.interp ((preR `st.star` preL) `st.star` (st.locks_invariant state)) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; FStar.Tactics.Effect.assert_by_tactic (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) (fun _ -> (); (norm [delta_only [`%weaker_lpre; `%par_lpre]])); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state
false
Vale.AES.AES_helpers.fsti
Vale.AES.AES_helpers.expand_key_128_def
val expand_key_128_def (key: seq nat32) (round: nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True)
val expand_key_128_def (key: seq nat32) (round: nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True)
let rec expand_key_128_def (key:seq nat32) (round:nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) = if round = 0 then Mkfour key.[0] key.[1] key.[2] key.[3] else round_key_128 (expand_key_128_def key (round - 1)) round
{ "file_name": "vale/code/crypto/aes/Vale.AES.AES_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 41, "start_col": 0, "start_line": 36 }
module Vale.AES.AES_helpers open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open FStar.Mul // syntax for seq accesses, s.[index] and s.[index] <- value unfold let (.[]) (#a:Type) (s:seq a) (i:nat{ i < length s}) : Tot a = index s i unfold let (.[]<-) = Seq.upd unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 // Redefine key expansion in terms of quad32 values rather than nat32 values, // then prove both definitions are equivalent. let round_key_128_rcon (prev:quad32) (rcon:nat32) : quad32 = let Mkfour v0 v1 v2 v3 = prev in let w0 = v0 *^ (sub_word (rot_word_LE v3) *^ rcon) in let w1 = v1 *^ w0 in let w2 = v2 *^ w1 in let w3 = v3 *^ w2 in Mkfour w0 w1 w2 w3 let round_key_128 (prev:quad32) (round:nat) : quad32 = round_key_128_rcon prev (aes_rcon (round - 1))
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.AES_helpers.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> round: Prims.nat -> Prims.Pure Vale.Def.Types_s.quad32
Prims.Pure
[]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Prims.nat", "Prims.op_Equality", "Prims.int", "Vale.Def.Words_s.Mkfour", "Vale.AES.AES_helpers.op_String_Access", "Prims.bool", "Vale.AES.AES_helpers.round_key_128", "Vale.AES.AES_helpers.expand_key_128_def", "Prims.op_Subtraction", "Vale.Def.Types_s.quad32", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.AES_common_s.AES_128", "Prims.l_True" ]
[ "recursion" ]
false
false
false
false
false
let rec expand_key_128_def (key: seq nat32) (round: nat) : Pure quad32 (requires is_aes_key_LE AES_128 key) (ensures fun _ -> True) =
if round = 0 then Mkfour key.[ 0 ] key.[ 1 ] key.[ 2 ] key.[ 3 ] else round_key_128 (expand_key_128_def key (round - 1)) round
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_par_ret
val step_par_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
val step_par_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f)
let step_par_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_par_ret_aux frame f, n)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 62, "end_line": 1239, "start_col": 0, "start_line": 1228 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0) let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n) let step_frame (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Frame (Ret _ _ _) _ _ -> step_frame_ret frame f | Frame #_ #_ #f_pre #_ #_ #_ f frame' f_frame' -> let m0 = get () in //To go from: // f_pre * frame' * frame * st.locks_invariant m0 to // f_pre * (frame' * frame) * st.locks_invariant m0 commute_star_par_l f_pre frame' frame (st.locks_invariant m0) m0; let Step next_fpre next_fpost next_flpre next_flpost f = step (frame' `st.star` frame) f in let m1 = get () in //To go in the other direction on the output memory m1 commute_star_par_l next_fpre frame' frame (st.locks_invariant m1) m1; Step (next_fpre `st.star` frame') (fun x -> next_fpost x `st.star` frame') (frame_lpre next_flpre f_frame') (frame_lpost next_flpre next_flpost f_frame') (Frame f frame' f_frame') let step_par_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Par #_ #aL #_ #_ #_ #_ (Ret pL xL lpL) #aR #_ #_ #_ #_ (Ret pR xR lpR) -> let lpost : l_post #st #(aL & aR) (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) = fun h0 (xL, xR) h1 -> lpL h0 xL h1 /\ lpR h0 xR h1 in Step (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) (fun h -> lpL h xL h /\ lpR h xR h) lpost (Ret (fun (xL, xR) -> pL xL `st.star` pR xR) (xL, xR) lpost), m0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)} -> Steel.Semantics.Hoare.MST.Mst (Steel.Semantics.Hoare.MST.step_result st a)
Steel.Semantics.Hoare.MST.Mst
[]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Par", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Par__item__aL", "Steel.Semantics.Hoare.MST.__proj__Par__item__preL", "Steel.Semantics.Hoare.MST.__proj__Par__item__postL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostL", "Steel.Semantics.Hoare.MST.__proj__Par__item__mL", "Steel.Semantics.Hoare.MST.__proj__Par__item__aR", "Steel.Semantics.Hoare.MST.__proj__Par__item__preR", "Steel.Semantics.Hoare.MST.__proj__Par__item__postR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostR", "Steel.Semantics.Hoare.MST.__proj__Par__item__mR", "FStar.Pervasives.Native.tuple2", "FStar.NMST.tape", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.step_par_ret_aux", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
false
true
false
false
false
let step_par_ret (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) =
NMSTATE?.reflect (fun (_, n) -> step_par_ret_aux frame f, n)
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_frame_ret_aux
val step_frame_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
val step_frame_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 58, "end_line": 1151, "start_col": 0, "start_line": 1134 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)} -> FStar.MST.MSTATE (Steel.Semantics.Hoare.MST.step_result st a)
FStar.MST.MSTATE
[]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Frame", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Frame__item__a", "Steel.Semantics.Hoare.MST.__proj__Frame__item__pre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__post", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpre", "Steel.Semantics.Hoare.MST.__proj__Frame__item__lpost", "Steel.Semantics.Hoare.MST.__proj__Frame__item__f", "Steel.Semantics.Hoare.MST.full_mem", "Steel.Semantics.Hoare.MST.fp_prop", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.Step", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.Ret", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
false
true
false
false
false
let step_frame_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#p: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre p) (frame: st.hprop) (f: m st a pre p lpre lpost {Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) =
M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step ((p x) `st.star` frame') (fun x -> (p x) `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> (p x) `st.star` frame') x lpost), m0)
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.t64_imm
val t64_imm : Vale.Interop.Base.td
let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 104, "end_line": 28, "start_col": 0, "start_line": 28 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.TD_ImmBuffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.Interop.Base.Mkbuffer_qualifiers", "Vale.Arch.HeapTypes_s.Secret" ]
[]
false
false
false
true
false
let t64_imm =
TD_ImmBuffer TUInt8 TUInt64 ({ modified = false; strict_disjointness = false; taint = MS.Secret })
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.t64_no_mod
val t64_no_mod : Vale.Interop.Base.td
let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 104, "end_line": 26, "start_col": 0, "start_line": 26 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.TD_Buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.Interop.Base.Mkbuffer_qualifiers", "Vale.Arch.HeapTypes_s.Secret" ]
[]
false
false
false
true
false
let t64_no_mod =
TD_Buffer TUInt8 TUInt64 ({ modified = false; strict_disjointness = false; taint = MS.Secret })
false
Steel.Semantics.Hoare.MST.fst
Steel.Semantics.Hoare.MST.step_par_ret_aux
val step_par_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
val step_par_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f)
let step_par_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Par #_ #aL #_ #_ #_ #_ (Ret pL xL lpL) #aR #_ #_ #_ #_ (Ret pR xR lpR) -> let lpost : l_post #st #(aL & aR) (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) = fun h0 (xL, xR) h1 -> lpL h0 xL h1 /\ lpR h0 xR h1 in Step (pL xL `st.star` pR xR) (fun (xL, xR) -> pL xL `st.star` pR xR) (fun h -> lpL h xL h /\ lpR h xR h) lpost (Ret (fun (xL, xR) -> pL xL `st.star` pR xR) (xL, xR) lpost), m0)
{ "file_name": "lib/steel/Steel.Semantics.Hoare.MST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 73, "end_line": 1226, "start_col": 0, "start_line": 1202 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Semantics.Hoare.MST module P = FStar.Preorder open FStar.Tactics open FStar.NMST (* * This module provides a semantic model for a combined effect of * divergence, state, and parallel composition of atomic actions. * * It is built over a monotonic state effect -- so that we can give * lock semantics using monotonicity * * It also builds a generic separation-logic-style program logic * for this effect, in a partial correctness setting. * It is also be possible to give a variant of this semantics for * total correctness. However, we specifically focus on partial correctness * here so that this semantics can be instantiated with lock operations, * which may deadlock. See ParTot.fst for a total-correctness variant of * these semantics. * * The program logic is specified in the Hoare-style pre- and postconditions *) /// Disabling projectors because we don't use them and they increase the typechecking time #push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \ --using_facts_from 'Prims FStar.Pervasives FStar.Preorder FStar.MST FStar.NMST Steel.Semantics.Hoare.MST'" (**** Begin state defn ****) /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers was more convenient for the proof done here. let symmetry #a (equals: a -> a -> prop) = forall x y. {:pattern (x `equals` y)} x `equals` y ==> y `equals` x let transitive #a (equals:a -> a -> prop) = forall x y z. x `equals` y /\ y `equals` z ==> x `equals` z let associative #a (equals: a -> a -> prop) (f: a -> a -> a)= forall x y z. f x (f y z) `equals` f (f x y) z let commutative #a (equals: a -> a -> prop) (f: a -> a -> a) = forall x y.{:pattern f x y} f x y `equals` f y x let is_unit #a (x:a) (equals: a -> a -> prop) (f:a -> a -> a) = forall y. {:pattern f x y \/ f y x} f x y `equals` y /\ f y x `equals` y let equals_ext #a (equals:a -> a -> prop) (f:a -> a -> a) = forall x1 x2 y. x1 `equals` x2 ==> f x1 y `equals` f x2 y let fp_heap_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (pre:hprop) = h:heap{interp pre h} let depends_only_on_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> prop) (fp: hprop) = forall (h0:fp_heap_0 interp fp) (h1:heap{disjoint h0 h1}). q h0 <==> q (join h0 h1) let fp_prop_0 (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint: heap -> heap -> prop) (join: (h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp:hprop) = p:(heap -> prop){p `(depends_only_on_0 interp disjoint join)` fp} noeq type st0 = { mem:Type u#2; core:mem -> mem; full_mem_pred: mem -> prop; locks_preorder:P.preorder (m:mem{full_mem_pred m}); hprop:Type u#2; locks_invariant: mem -> hprop; disjoint: mem -> mem -> prop; join: h0:mem -> h1:mem{disjoint h0 h1} -> mem; interp: hprop -> mem -> prop; emp:hprop; star: hprop -> hprop -> hprop; equals: hprop -> hprop -> prop; } /// disjointness is symmetric let disjoint_sym (st:st0) = forall h0 h1. st.disjoint h0 h1 <==> st.disjoint h1 h0 let disjoint_join (st:st0) = forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.disjoint m0 m1 /\ st.disjoint m0 m2 /\ st.disjoint (st.join m0 m1) m2 /\ st.disjoint (st.join m0 m2) m1 let join_commutative (st:st0 { disjoint_sym st }) = forall m0 m1. st.disjoint m0 m1 ==> st.join m0 m1 == st.join m1 m0 let join_associative (st:st0{disjoint_join st})= forall m0 m1 m2. st.disjoint m1 m2 /\ st.disjoint m0 (st.join m1 m2) ==> st.join m0 (st.join m1 m2) == st.join (st.join m0 m1) m2 //////////////////////////////////////////////////////////////////////////////// let interp_extensionality #r #s (equals:r -> r -> prop) (f:r -> s -> prop) = forall x y h. {:pattern equals x y; f x h} equals x y /\ f x h ==> f y h let affine (st:st0) = forall r0 r1 s. {:pattern (st.interp (r0 `st.star` r1) s) } st.interp (r0 `st.star` r1) s ==> st.interp r0 s //////////////////////////////////////////////////////////////////////////////// let depends_only_on (#st:st0) (q:st.mem -> prop) (fp: st.hprop) = depends_only_on_0 st.interp st.disjoint st.join q fp let fp_prop (#st:st0) (fp:st.hprop) = fp_prop_0 st.interp st.disjoint st.join fp let lemma_weaken_depends_only_on (#st:st0{affine st}) (fp0 fp1:st.hprop) (q:fp_prop fp0) : Lemma (q `depends_only_on` (fp0 `st.star` fp1)) = () let st_laws (st:st0) = (* standard laws about the equality relation *) symmetry st.equals /\ transitive st.equals /\ interp_extensionality st.equals st.interp /\ (* standard laws for star forming a CM *) associative st.equals st.star /\ commutative st.equals st.star /\ is_unit st.emp st.equals st.star /\ equals_ext st.equals st.star /\ (* We're working in an affine interpretation of SL *) affine st /\ (* laws about disjoint and join *) disjoint_sym st /\ disjoint_join st /\ join_commutative st /\ join_associative st let st = s:st0 { st_laws s } (**** End state defn ****) (**** Begin expects, provides, requires, and ensures defns ****) /// expects (the heap assertion expected by a computation) is simply an st.hprop /// /// provides, or the post heap assertion, is a st.hprop on [a]-typed result type post_t (st:st) (a:Type) = a -> st.hprop /// requires is a heap predicate that depends only on a pre heap assertion /// (where the notion of `depends only on` is defined above as part of the state definition) /// /// we call the type l_pre for logical precondition let l_pre (#st:st) (pre:st.hprop) = fp_prop pre /// ensures is a 2-state postcondition of type heap -> a -> heap -> prop /// /// To define ensures, we need a notion of depends_only_on_2 /// /// Essentially, in the first heap argument, postconditions depend only on the expects hprop /// and in the second heap argument, postconditions depend only on the provides hprop /// /// Also note that the support for depends_only_on_2 is not required from the underlying memory model let depends_only_on_0_2 (#a:Type) (#heap:Type) (#hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (q:heap -> a -> heap -> prop) (fp_pre:hprop) (fp_post:a -> hprop) = //can join any disjoint heap to the pre-heap and q is still valid (forall x (h_pre:fp_heap_0 interp fp_pre) h_post (h:heap{disjoint h_pre h}). q h_pre x h_post <==> q (join h_pre h) x h_post) /\ //can join any disjoint heap to the post-heap and q is still valid (forall x h_pre (h_post:fp_heap_0 interp (fp_post x)) (h:heap{disjoint h_post h}). q h_pre x h_post <==> q h_pre x (join h_post h)) /// Abbreviations for two-state depends let fp_prop_0_2 (#a:Type) (#heap #hprop:Type) (interp:hprop -> heap -> prop) (disjoint:heap -> heap -> prop) (join:(h0:heap -> h1:heap{disjoint h0 h1} -> heap)) (fp_pre:hprop) (fp_post:a -> hprop) = q:(heap -> a -> heap -> prop){depends_only_on_0_2 interp disjoint join q fp_pre fp_post} let depends_only_on2 (#st:st0) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = depends_only_on_0_2 st.interp st.disjoint st.join q fp_pre fp_post let fp_prop2 (#st:st0) (#a:Type) (fp_pre:st.hprop) (fp_post:a -> st.hprop) = q:(st.mem -> a -> st.mem -> prop){depends_only_on2 q fp_pre fp_post} /// Finally the type of 2-state postconditions let l_post (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) = fp_prop2 pre post (**** End expects, provides, requires, and ensures defns ****) open FStar.NMSTTotal let full_mem (st:st) = m:st.mem{st.full_mem_pred m} effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATE a (full_mem st) st.locks_preorder req ens effect MstTot (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) = NMSTATETOT a (full_mem st) st.locks_preorder req ens let get (#st:st) () : MstTot (full_mem st) (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) = get () (**** Begin interface of actions ****) /// Actions are essentially state transformers that preserve frames let post_preserves_frame (#st:st) (post frame:st.hprop) (m0 m1:st.mem) = st.interp (post `st.star` frame `st.star` (st.locks_invariant m1)) m1 /\ (forall (f_frame:fp_prop frame). f_frame (st.core m0) == f_frame (st.core m1)) let action_t (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> Mst a (requires fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) let action_t_tot (#st:st) (#a:Type) (pre:st.hprop) (post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) = frame:st.hprop -> MstTot a (requires fun m0 -> st.interp (pre `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0)) (ensures fun m0 x m1 -> post_preserves_frame (post x) frame m0 m1 /\ lpost (st.core m0) x (st.core m1)) (**** End interface of actions ****) (**** Begin definition of the computation AST ****) /// Gadgets for building lpre- and lpostconditions for various nodes /// Return node is parametric in provides and ensures let return_lpre (#st:st) (#a:Type) (#post:post_t st a) (x:a) (lpost:l_post (post x) post) : l_pre (post x) = fun h -> lpost h x h let frame_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#frame:st.hprop) (f_frame:fp_prop frame) : l_pre (pre `st.star` frame) = fun h -> lpre h /\ f_frame h let frame_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#frame:st.hprop) (f_frame:fp_prop frame) : l_post (pre `st.star` frame) (fun x -> post x `st.star` frame) = fun h0 x h1 -> lpre h0 /\ lpost h0 x h1 /\ f_frame h1 /// The bind rule bakes in weakening of requires / ensures let bind_lpre (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (lpre_b:(x:a -> l_pre (post_a x))) : l_pre pre = fun h -> lpre_a h /\ (forall (x:a) h1. lpost_a h x h1 ==> lpre_b x h1) let bind_lpost (#st:st) (#a:Type) (#pre:st.hprop) (#post_a:post_t st a) (lpre_a:l_pre pre) (lpost_a:l_post pre post_a) (#b:Type) (#post_b:post_t st b) (lpost_b:(x:a -> l_post (post_a x) post_b)) : l_post pre post_b = fun h0 y h2 -> lpre_a h0 /\ (exists x h1. lpost_a h0 x h1 /\ (lpost_b x) h1 y h2) /// Parallel composition is pointwise let par_lpre (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#preR:st.hprop) (lpreR:l_pre preR) : l_pre (preL `st.star` preR) = fun h -> lpreL h /\ lpreR h let par_lpost (#st:st) (#aL:Type) (#preL:st.hprop) (#postL:post_t st aL) (lpreL:l_pre preL) (lpostL:l_post preL postL) (#aR:Type) (#preR:st.hprop) (#postR:post_t st aR) (lpreR:l_pre preR) (lpostR:l_post preR postR) : l_post (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) = fun h0 (xL, xR) h1 -> lpreL h0 /\ lpreR h0 /\ lpostL h0 xL h1 /\ lpostR h0 xR h1 let weaker_pre (#st:st) (pre:st.hprop) (next_pre:st.hprop) = forall (h:st.mem) (frame:st.hprop). st.interp (pre `st.star` frame) h ==> st.interp (next_pre `st.star` frame) h let stronger_post (#st:st) (#a:Type u#a) (post next_post:post_t st a) = forall (x:a) (h:st.mem) (frame:st.hprop). st.interp (next_post x `st.star` frame) h ==> st.interp (post x `st.star` frame) h let weakening_ok (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpre:l_pre pre) (lpost:l_post pre post) (#wpre:st.hprop) (#wpost:post_t st a) (wlpre:l_pre wpre) (wlpost:l_post wpre wpost) = weaker_pre wpre pre /\ stronger_post wpost post /\ (forall h. wlpre h ==> lpre h) /\ (forall h0 x h1. lpost h0 x h1 ==> wlpost h0 x h1) /// Setting the flag just to reduce the time to typecheck the type m noeq type m (st:st) : a:Type u#a -> pre:st.hprop -> post:post_t st a -> l_pre pre -> l_post pre post -> Type = | Ret: #a:Type u#a -> post:post_t st a -> x:a -> lpost:l_post (post x) post -> m st a (post x) post (return_lpre #_ #_ #post x lpost) lpost | Bind: #a:Type u#a -> #pre:st.hprop -> #post_a:post_t st a -> #lpre_a:l_pre pre -> #lpost_a:l_post pre post_a -> #b:Type u#a -> #post_b:post_t st b -> #lpre_b:(x:a -> l_pre (post_a x)) -> #lpost_b:(x:a -> l_post (post_a x) post_b) -> f:m st a pre post_a lpre_a lpost_a -> g:(x:a -> Dv (m st b (post_a x) post_b (lpre_b x) (lpost_b x))) -> m st b pre post_b (bind_lpre lpre_a lpost_a lpre_b) (bind_lpost lpre_a lpost_a lpost_b) | Act: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:action_t #st #a pre post lpre lpost -> m st a pre post lpre lpost | Frame: #a:Type -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> f:m st a pre post lpre lpost -> frame:st.hprop -> f_frame:fp_prop frame -> m st a (pre `st.star` frame) (fun x -> post x `st.star` frame) (frame_lpre lpre f_frame) (frame_lpost lpre lpost f_frame) | Par: #aL:Type u#a -> #preL:st.hprop -> #postL:post_t st aL -> #lpreL:l_pre preL -> #lpostL:l_post preL postL -> mL:m st aL preL postL lpreL lpostL -> #aR:Type u#a -> #preR:st.hprop -> #postR:post_t st aR -> #lpreR:l_pre preR -> #lpostR:l_post preR postR -> mR:m st aR preR postR lpreR lpostR -> m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR) (par_lpre lpreL lpreR) (par_lpost lpreL lpostL lpreR lpostR) | Weaken: #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> #wpre:st.hprop -> #wpost:post_t st a -> wlpre:l_pre wpre -> wlpost:l_post wpre wpost -> _:squash (weakening_ok lpre lpost wlpre wlpost) -> m st a pre post lpre lpost -> m st a wpre wpost wlpre wlpost (**** End definition of the computation AST ****) (**** Stepping relation ****) /// All steps preserve frames noeq type step_result (st:st) (a:Type u#a) = | Step: next_pre:st.hprop -> next_post:post_t st a -> lpre:l_pre next_pre -> lpost:l_post next_pre next_post -> m st a next_pre next_post lpre lpost -> step_result st a (**** Type of the single-step interpreter ****) /// Interpreter is setup as a Div function from computation trees to computation trees /// /// While the requires for the Div is standard (that the expects hprop holds and requires is valid), /// the ensures is interesting /// /// As the computation evolves, the requires and ensures associated with the computation graph nodes /// also evolve /// But they evolve systematically: preconditions become weaker and postconditions become stronger /// /// Consider { req } c | st { ens } ~~> { req1 } c1 | st1 { ens1 } /// /// Then, req st ==> req1 st1 /\ /// (forall x st_final. ens1 st1 x st_final ==> ens st x st_final) unfold let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> Type0 = fun m0 -> st.interp (pre `st.star` frame `st.star` st.locks_invariant m0) m0 /\ lpre (st.core m0) let weaker_lpre (#st:st) (#pre:st.hprop) (lpre:l_pre pre) (#next_pre:st.hprop) (next_lpre:l_pre next_pre) (m0 m1:st.mem) = lpre (st.core m0) ==> next_lpre (st.core m1) let stronger_lpost (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (#next_pre:st.hprop) #next_post (next_lpost:l_post next_pre next_post) (m0 m1:st.mem) = forall (x:a) (h_final:st.mem). next_lpost (st.core m1) x h_final ==> lpost (st.core m0) x h_final unfold let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost) : st.mem -> step_result st a -> st.mem -> Type0 = fun m0 r m1 -> let Step next_pre next_post next_lpre next_lpost _ = r in post_preserves_frame next_pre frame m0 m1 /\ stronger_post post next_post /\ next_lpre (st.core m1) /\ //we are writing it here explicitly, //but it is derivable from weaker_lpre //removing it is also fine for the proofs weaker_lpre lpre next_lpre m0 m1 /\ stronger_lpost lpost next_lpost m0 m1 /// The type of the stepping function type step_t = #st:st -> #a:Type u#a -> #pre:st.hprop -> #post:post_t st a -> #lpre:l_pre pre -> #lpost:l_post pre post -> frame:st.hprop -> f:m st a pre post lpre lpost -> Mst (step_result st a) (step_req frame f) (step_ens frame f) (**** Auxiliary lemmas ****) /// Some AC lemmas on `st.star` let apply_assoc (#st:st) (p q r:st.hprop) : Lemma (st.equals (p `st.star` (q `st.star` r)) ((p `st.star` q) `st.star` r)) = () let equals_ext_left (#st:st) (p q r:st.hprop) : Lemma (requires p `st.equals` q) (ensures (p `st.star` r) `st.equals` (q `st.star` r)) = () let equals_ext_right (#st:st) (p q r:st.hprop) : Lemma (requires q `st.equals` r) (ensures (p `st.star` q) `st.equals` (p `st.star` r)) = calc (st.equals) { p `st.star` q; (st.equals) { } q `st.star` p; (st.equals) { } r `st.star` p; (st.equals) { } p `st.star` r; } let commute_star_right (#st:st) (p q r:st.hprop) : Lemma ((p `st.star` (q `st.star` r)) `st.equals` (p `st.star` (r `st.star` q))) = calc (st.equals) { p `st.star` (q `st.star` r); (st.equals) { equals_ext_right p (q `st.star` r) (r `st.star` q) } p `st.star` (r `st.star` q); } let assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (q `st.star` (r `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) (q `st.star` (r `st.star` s)) } p `st.star` (q `st.star` (r `st.star` s)); } let commute_assoc_star_right (#st:st) (p q r s:st.hprop) : Lemma ((p `st.star` ((q `st.star` r) `st.star` s)) `st.equals` (p `st.star` (r `st.star` (q `st.star` s)))) = calc (st.equals) { p `st.star` ((q `st.star` r) `st.star` s); (st.equals) { equals_ext_right p ((q `st.star` r) `st.star` s) ((r `st.star` q) `st.star` s) } p `st.star` ((r `st.star` q) `st.star` s); (st.equals) { assoc_star_right p r q s } p `st.star` (r `st.star` (q `st.star` s)); } let commute_star_par_l (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (p `st.star` (q `st.star` r) `st.star` s) m0) = assert ((p `st.star` q `st.star` r `st.star` s) `st.equals` (p `st.star` (q `st.star` r) `st.star` s)) let commute_star_par_r (#st:st) (p q r s:st.hprop) (m0:st.mem) : Lemma (st.interp (p `st.star` q `st.star` r `st.star` s) m0 <==> st.interp (q `st.star` (p `st.star` r) `st.star` s) m0) = calc (st.equals) { p `st.star` q `st.star` r `st.star` s; (st.equals) { } q `st.star` p `st.star` r `st.star` s; (st.equals) { } q `st.star` (p `st.star` r) `st.star` s; } /// Apply extensionality manually, control proofs let apply_interp_ext (#st:st) (p q:st.hprop) (m:st.mem) : Lemma (requires (st.interp p m /\ p `st.equals` q)) (ensures st.interp q m) = () let weaken_fp_prop (#st:st) (frame frame':st.hprop) (m0 m1:st.mem) : Lemma (requires forall (f_frame:fp_prop (frame `st.star` frame')). f_frame (st.core m0) == f_frame (st.core m1)) (ensures forall (f_frame:fp_prop frame'). f_frame (st.core m0) == f_frame (st.core m1)) = () let depends_only_on_commutes_with_weaker (#st:st) (q:st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) : Lemma (requires depends_only_on q fp /\ weaker_pre fp_next fp) (ensures depends_only_on q fp_next) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) let depends_only_on2_commutes_with_weaker (#st:st) (#a:Type) (q:st.mem -> a -> st.mem -> prop) (fp:st.hprop) (fp_next:st.hprop) (fp_post:a -> st.hprop) : Lemma (requires depends_only_on2 q fp fp_post /\ weaker_pre fp_next fp) (ensures depends_only_on2 q fp_next fp_post) = assert (forall (h0:fp_heap_0 st.interp fp_next). st.interp (fp_next `st.star` st.emp) h0) /// Lemma frame_post_for_par is used in the par proof /// /// E.g. in the par rule, when L takes a step, we can frame the requires of R /// by using the preserves_frame property of the stepping relation /// /// However we also need to frame the ensures of R, for establishing stronger_post /// /// Basically, we need: /// /// forall x h_final. postR prev_state x h_final <==> postR next_state x h_final /// /// (the proof only requires the reverse implication, but we can prove iff) /// /// To prove this, we rely on the framing of all frame fp props provides by the stepping relation /// /// To use it, we instantiate the fp prop with inst_heap_prop_for_par let inst_heap_prop_for_par (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (state:st.mem) : fp_prop pre = fun h -> forall x final_state. lpost h x final_state <==> lpost (st.core state) x final_state let frame_post_for_par_tautology (#st:st) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) (m0:st.mem) : Lemma (inst_heap_prop_for_par lpost_f m0 (st.core m0)) = () let frame_post_for_par_aux (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures inst_heap_prop_for_par lpost_f m0 (st.core m0) <==> inst_heap_prop_for_par lpost_f m0 (st.core m1)) = () let frame_post_for_par (#st:st) (pre_s post_s:st.hprop) (m0 m1:st.mem) (#a:Type) (#pre_f:st.hprop) (#post_f:post_t st a) (lpre_f:l_pre pre_f) (lpost_f:l_post pre_f post_f) : Lemma (requires post_preserves_frame post_s pre_f m0 m1 /\ st.interp ((pre_s `st.star` pre_f) `st.star` st.locks_invariant m0) m0) (ensures (lpre_f (st.core m0) <==> lpre_f (st.core m1)) /\ (forall (x:a) (final_state:st.mem). lpost_f (st.core m0) x final_state <==> lpost_f (st.core m1) x final_state)) = frame_post_for_par_tautology lpost_f m0; frame_post_for_par_aux pre_s post_s m0 m1 lpost_f /// Finally lemmas for proving that in the par rules preconditions get weaker /// and postconditions get stronger let par_weaker_lpre_and_stronger_lpost_l (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#next_preL:st.hprop) (#next_postL:post_t st aL) (next_lpreL:l_pre next_preL) (next_lpostL:l_post next_preL next_postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreL next_lpreL state next_state /\ stronger_lpost lpostL next_lpostL state next_state /\ post_preserves_frame next_preL preR state next_state /\ lpreL (st.core state) /\ lpreR (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` st.locks_invariant state) state) (ensures weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost next_lpreL next_lpostL lpreR lpostR) state next_state) = frame_post_for_par preL next_preL state next_state lpreR lpostR; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre next_lpreL lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]) let par_weaker_lpre_and_stronger_lpost_r (#st:st) (#preL:st.hprop) (lpreL:l_pre preL) (#aL:Type) (#postL:post_t st aL) (lpostL:l_post preL postL) (#preR:st.hprop) (lpreR:l_pre preR) (#aR:Type) (#postR:post_t st aR) (lpostR:l_post preR postR) (#next_preR:st.hprop) (#next_postR:post_t st aR) (next_lpreR:l_pre next_preR) (next_lpostR:l_post next_preR next_postR) (frame:st.hprop) (state next_state:st.mem) : Lemma (requires weaker_lpre lpreR next_lpreR state next_state /\ stronger_lpost lpostR next_lpostR state next_state /\ post_preserves_frame next_preR (preL `st.star` frame) state next_state /\ lpreR (st.core state) /\ lpreL (st.core state) /\ st.interp ((preL `st.star` preR) `st.star` frame `st.star` st.locks_invariant state) state) (ensures st.interp ((preL `st.star` next_preR) `st.star` frame `st.star` st.locks_invariant next_state) next_state /\ weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state /\ stronger_lpost (par_lpost lpreL lpostL lpreR lpostR) (par_lpost lpreL lpostL next_lpreR next_lpostR) state next_state) = calc (st.equals) { preL `st.star` preR `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` frame `st.star` st.locks_invariant state; (st.equals) { } preR `st.star` preL `st.star` (frame `st.star` st.locks_invariant state); (st.equals) { equals_ext_right (preR `st.star` preL) (frame `st.star` st.locks_invariant state) (st.locks_invariant state `st.star` frame) } preR `st.star` preL `st.star` (st.locks_invariant state `st.star` frame); (st.equals) { } preR `st.star` preL `st.star` st.locks_invariant state `st.star` frame; }; assert (st.interp (preR `st.star` preL `st.star` st.locks_invariant state) state); frame_post_for_par preR next_preR state next_state lpreL lpostL; assert (weaker_lpre (par_lpre lpreL lpreR) (par_lpre lpreL next_lpreR) state next_state) by (norm [delta_only [`%weaker_lpre; `%par_lpre] ]); commute_star_par_r preL next_preR frame (st.locks_invariant next_state) next_state #push-options "--warn_error -271" let stronger_post_par_r (#st:st) (#aL #aR:Type u#a) (postL:post_t st aL) (postR:post_t st aR) (next_postR:post_t st aR) : Lemma (requires stronger_post postR next_postR) (ensures forall xL xR frame h. st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h ==> st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) = let aux xL xR frame h : Lemma (requires st.interp ((postL xL `st.star` next_postR xR) `st.star` frame) h) (ensures st.interp ((postL xL `st.star` postR xR) `st.star` frame) h) [SMTPat ()] = calc (st.equals) { (postL xL `st.star` next_postR xR) `st.star` frame; (st.equals) { } (next_postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } next_postR xR `st.star` (postL xL `st.star` frame); }; assert (st.interp (next_postR xR `st.star` (postL xL `st.star` frame)) h); assert (st.interp (postR xR `st.star` (postL xL `st.star` frame)) h); calc (st.equals) { postR xR `st.star` (postL xL `st.star` frame); (st.equals) { } (postR xR `st.star` postL xL) `st.star` frame; (st.equals) { } (postL xL `st.star` postR xR) `st.star` frame; } in () #pop-options (**** Begin stepping functions ****) let step_ret (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Ret? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> let Ret p x lp = f in Step (p x) p lpre lpost f, n) let lpost_ret_act (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (lpost:l_post pre post) (x:a) (state:st.mem) : l_post (post x) post = fun _ x h1 -> lpost (st.core state) x h1 let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Act? f}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = let m0 = get () in let Act #_ #_ #_ #_ #_ #_ f = f in let x = f frame in let lpost : l_post (post x) post = lpost_ret_act lpost x m0 in Step (post x) post (fun h -> lpost h x h) lpost (Ret post x lpost) module M = FStar.MST let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Bind #_ #_ #_ #_ #_ #_ #_ #post_b #lpre_b #lpost_b (Ret p x _) g -> Step (p x) post_b (lpre_b x) (lpost_b x) (g x), m0) let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f /\ Ret? (Bind?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux frame f, n) #push-options "--z3rlimit 40" let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre post) (frame:st.hprop) (f:m st a pre post lpre lpost{Bind? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Bind (Ret _ _ _) _ -> step_bind_ret frame f | Bind #_ #b #_ #post_a #_ #_ #_ #post_b #lpre_b #lpost_b f g -> let Step next_pre next_post next_lpre next_lpost f = step frame f in let lpre_b : (x:b -> l_pre (next_post x)) = fun x -> depends_only_on_commutes_with_weaker (lpre_b x) (post_a x) (next_post x); lpre_b x in let lpost_b : (x:b -> l_post (next_post x) post_b) = fun x -> depends_only_on2_commutes_with_weaker (lpost_b x) (post_a x) (next_post x) post_b; lpost_b x in let g : (x:b -> Dv (m st _ (next_post x) post_b (lpre_b x) (lpost_b x))) = fun x -> Weaken (lpre_b x) (lpost_b x) () (g x) in let m1 = get () in assert ((bind_lpre next_lpre next_lpost lpre_b) (st.core m1)) by norm ([delta_only [`%bind_lpre]]); Step next_pre post_b (bind_lpre next_lpre next_lpost lpre_b) (bind_lpost next_lpre next_lpost lpost_b) (Bind f g) #pop-options let step_frame_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) = M.MSTATE?.reflect (fun m0 -> match f with | Frame (Ret p x lp) frame' _ -> Step (p x `st.star` frame') (fun x -> p x `st.star` frame') (fun h -> lpost h x h) lpost (Ret (fun x -> p x `st.star` frame') x lpost), m0) let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f /\ Ret? (Frame?.f f)}) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = NMSTATE?.reflect (fun (_, n) -> step_frame_ret_aux frame f, n) let step_frame (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a) (#lpre:l_pre pre) (#lpost:l_post pre p) (frame:st.hprop) (f:m st a pre p lpre lpost{Frame? f}) (step:step_t) : Mst (step_result st a) (step_req frame f) (step_ens frame f) = match f with | Frame (Ret _ _ _) _ _ -> step_frame_ret frame f | Frame #_ #_ #f_pre #_ #_ #_ f frame' f_frame' -> let m0 = get () in //To go from: // f_pre * frame' * frame * st.locks_invariant m0 to // f_pre * (frame' * frame) * st.locks_invariant m0 commute_star_par_l f_pre frame' frame (st.locks_invariant m0) m0; let Step next_fpre next_fpost next_flpre next_flpost f = step (frame' `st.star` frame) f in let m1 = get () in //To go in the other direction on the output memory m1 commute_star_par_l next_fpre frame' frame (st.locks_invariant m1) m1; Step (next_fpre `st.star` frame') (fun x -> next_fpost x `st.star` frame') (frame_lpre next_flpre f_frame') (frame_lpost next_flpre next_flpost f_frame') (Frame f frame' f_frame')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.NMST.fst.checked", "FStar.MST.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Steel.Semantics.Hoare.MST.fst" }
[ { "abbrev": true, "full_module": "FStar.MST", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.NMSTTotal", "short_module": null }, { "abbrev": false, "full_module": "FStar.NMST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "Steel.Semantics.Hoare", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 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": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frame: Mkst0?.hprop st -> f: Steel.Semantics.Hoare.MST.m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)} -> FStar.MST.MSTATE (Steel.Semantics.Hoare.MST.step_result st a)
FStar.MST.MSTATE
[]
[]
[ "Steel.Semantics.Hoare.MST.st", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop", "Steel.Semantics.Hoare.MST.post_t", "Steel.Semantics.Hoare.MST.l_pre", "Steel.Semantics.Hoare.MST.l_post", "Steel.Semantics.Hoare.MST.m", "Prims.l_and", "Prims.b2t", "Steel.Semantics.Hoare.MST.uu___is_Par", "Steel.Semantics.Hoare.MST.uu___is_Ret", "Steel.Semantics.Hoare.MST.__proj__Par__item__aL", "Steel.Semantics.Hoare.MST.__proj__Par__item__preL", "Steel.Semantics.Hoare.MST.__proj__Par__item__postL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreL", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostL", "Steel.Semantics.Hoare.MST.__proj__Par__item__mL", "Steel.Semantics.Hoare.MST.__proj__Par__item__aR", "Steel.Semantics.Hoare.MST.__proj__Par__item__preR", "Steel.Semantics.Hoare.MST.__proj__Par__item__postR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpreR", "Steel.Semantics.Hoare.MST.__proj__Par__item__lpostR", "Steel.Semantics.Hoare.MST.__proj__Par__item__mR", "Steel.Semantics.Hoare.MST.full_mem", "FStar.Pervasives.Native.Mktuple2", "Steel.Semantics.Hoare.MST.step_result", "Steel.Semantics.Hoare.MST.Step", "FStar.Pervasives.Native.tuple2", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Prims.prop", "Steel.Semantics.Hoare.MST.Ret", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_preorder", "Steel.Semantics.Hoare.MST.step_req", "Steel.Semantics.Hoare.MST.step_ens" ]
[]
false
true
false
false
false
let step_par_ret_aux (#st: st) (#a: Type) (#pre: st.hprop) (#post: post_t st a) (#lpre: l_pre pre) (#lpost: l_post pre post) (frame: st.hprop) (f: m st a pre post lpre lpost {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}) : M.MSTATE (step_result st a) (full_mem st) st.locks_preorder (step_req frame f) (step_ens frame f) =
M.MSTATE?.reflect (fun m0 -> match f with | Par #_ #aL #_ #_ #_ #_ (Ret pL xL lpL) #aR #_ #_ #_ #_ (Ret pR xR lpR) -> let lpost:l_post #st #(aL & aR) ((pL xL) `st.star` (pR xR)) (fun (xL, xR) -> (pL xL) `st.star` (pR xR)) = fun h0 (xL, xR) h1 -> lpL h0 xL h1 /\ lpR h0 xR h1 in Step ((pL xL) `st.star` (pR xR)) (fun (xL, xR) -> (pL xL) `st.star` (pR xR)) (fun h -> lpL h xL h /\ lpR h xR h) lpost (Ret (fun (xL, xR) -> (pL xL) `st.star` (pR xR)) (xL, xR) lpost), m0)
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.t64_mod
val t64_mod : Vale.Interop.Base.td
let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 24, "start_col": 0, "start_line": 24 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.TD_Buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.Interop.Base.default_bq" ]
[]
false
false
false
true
false
let t64_mod =
TD_Buffer TUInt8 TUInt64 default_bq
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.b64
val b64 : Type0
let b64 = buf_t TUInt8 TUInt64
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 20, "start_col": 0, "start_line": 20 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.buf_t", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64" ]
[]
false
false
false
true
true
let b64 =
buf_t TUInt8 TUInt64
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.ib64
val ib64 : Type0
let ib64 = ibuf_t TUInt8 TUInt64
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 22, "start_col": 0, "start_line": 22 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.ibuf_t", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64" ]
[]
false
false
false
true
true
let ib64 =
ibuf_t TUInt8 TUInt64
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.call_c_normal_t
val call_c_normal_t:normal call_c_t
val call_c_normal_t:normal call_c_t
let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 48, "start_col": 0, "start_line": 48 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.Pervasives.norm [ FStar.Pervasives.iota; FStar.Pervasives.zeta; FStar.Pervasives.delta_attr ["Vale.Arch.HeapTypes_s.__reduce__"; "FStar.BigOps.__reduce__"]; FStar.Pervasives.delta_only [ "Vale.Interop.Base.uu___is_TD_Buffer"; "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok"; "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs"; "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags"; "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap"; "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack"; "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint"; "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace"; "FStar.FunctionalExtensionality.on_dom"; "FStar.FunctionalExtensionality.on"; "FStar.List.Tot.Base.fold_right_gtot"; "FStar.List.Tot.Base.map_gtot"; "FStar.List.Tot.Base.length"; "FStar.Pervasives.Native.fst"; "FStar.Pervasives.Native.snd"; "FStar.Pervasives.Native.__proj__Mktuple2__item___1"; "FStar.Pervasives.Native.__proj__Mktuple2__item___2" ]; FStar.Pervasives.primops; FStar.Pervasives.simplify ] Vale.AsLowStar.Test.call_c_t <: Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.as_normal_t", "Vale.AsLowStar.Test.call_c_t", "Vale.AsLowStar.Test.call_c" ]
[]
false
false
false
false
false
let call_c_normal_t:normal call_c_t =
as_normal_t #call_c_t call_c
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.vm_post
val vm_post:VSig.vale_post vm_dom
val vm_post:VSig.vale_post vm_dom
let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 90, "end_line": 75, "start_col": 0, "start_line": 68 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_post Vale.AsLowStar.Test.vm_dom
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.b64", "Vale.AsLowStar.Test.ib64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "Vale.Test.X64.Vale_memcpy.va_ens_Memcpy", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Prims.prop" ]
[]
false
false
false
true
false
let vm_post:VSig.vale_post vm_dom =
fun (c: V.va_code) (dst: b64) (src: ib64) (va_s0: V.va_state) (va_s1: V.va_state) (f: V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.vm_pre
val vm_pre:VSig.vale_pre vm_dom
val vm_pre:VSig.vale_pre vm_dom
let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src)
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 65, "start_col": 0, "start_line": 60 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_pre Vale.AsLowStar.Test.vm_dom
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.b64", "Vale.AsLowStar.Test.ib64", "Vale.X64.Decls.va_state", "Vale.Test.X64.Vale_memcpy.va_req_Memcpy", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Prims.prop" ]
[]
false
false
false
true
false
let vm_pre:VSig.vale_pre vm_dom =
fun (c: V.va_code) (dst: b64) (src: ib64) (va_s0: V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src)
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.code_Memcpy
val code_Memcpy : Vale.X64.Decls.va_code
let code_Memcpy = VM.va_code_Memcpy IA.win
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 110, "start_col": 0, "start_line": 110 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma'
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Vale.Test.X64.Vale_memcpy.va_code_Memcpy", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
false
let code_Memcpy =
VM.va_code_Memcpy IA.win
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.vm_dom
val vm_dom : Prims.list Vale.Interop.Base.td
let vm_dom = [t64_mod; t64_imm]
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 56, "start_col": 0, "start_line": 56 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Vale.Interop.Base.td", "Vale.AsLowStar.Test.t64_mod", "Vale.AsLowStar.Test.t64_imm", "Prims.Nil" ]
[]
false
false
false
true
false
let vm_dom =
[t64_mod; t64_imm]
false
Pulse.Show.fst
Pulse.Show.showable_list
[@@ FStar.Tactics.Typeclasses.tcinstance] val showable_list: a: Type -> tac_showable a -> tac_showable (list a)
[@@ FStar.Tactics.Typeclasses.tcinstance] val showable_list: a: Type -> tac_showable a -> tac_showable (list a)
instance showable_list (a:Type) (_ : tac_showable a) : tac_showable (list a) = { show = string_of_list show; }
{ "file_name": "lib/steel/pulse/Pulse.Show.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 52, "start_col": 0, "start_line": 50 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Show open FStar.Tactics open FStar.Tactics.Typeclasses open Pulse.Typing open Pulse.Syntax.Base open Pulse.Syntax.Printer class tac_showable (a:Type) = { show : a -> Tac string; } instance _ : tac_showable string = { show = (fun s -> s); } instance _ : tac_showable unit = { show = (fun () -> "()"); } instance _ : tac_showable bool = { show = (fun b -> string_of_bool b); } instance _ : tac_showable int = { show = (fun b -> string_of_int b); } instance showable_option (a:Type) (_ : tac_showable a) : tac_showable (option a) = { show = (function None -> "None" | Some v -> "Some " ^ show v); }
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Show.fst" }
[ { "abbrev": false, "full_module": "Pulse.Syntax.Printer", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> _: Pulse.Show.tac_showable a -> Pulse.Show.tac_showable (Prims.list a)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Show.tac_showable", "Pulse.Show.Mktac_showable", "Prims.list", "FStar.Tactics.Util.string_of_list", "Pulse.Show.show" ]
[]
false
false
false
true
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let showable_list (a: Type) (_: tac_showable a) : tac_showable (list a) =
{ show = string_of_list show }
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_Memcpy_normal_t
val lowstar_Memcpy_normal_t : Vale.Interop.Base.normal Vale.AsLowStar.Test.lowstar_Memcpy_t
let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 131, "start_col": 0, "start_line": 130 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.normal Vale.AsLowStar.Test.lowstar_Memcpy_t
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.as_normal_t", "Vale.AsLowStar.Test.lowstar_Memcpy_t", "Vale.AsLowStar.Test.lowstar_Memcpy" ]
[]
false
false
false
true
false
let lowstar_Memcpy_normal_t =
as_normal_t #lowstar_Memcpy_t lowstar_Memcpy
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.code_aesni
val code_aesni : Vale.X64.Decls.va_code
let code_aesni = VC.va_code_Check_aesni_stdcall IA.win
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 234, "start_col": 0, "start_line": 234 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma'
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Vale.Lib.X64.Cpuidstdcall.va_code_Check_aesni_stdcall", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
false
let code_aesni =
VC.va_code_Check_aesni_stdcall IA.win
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.aesni_pre
val aesni_pre:VSig.vale_pre aesni_dom
val aesni_pre:VSig.vale_pre aesni_dom
let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 195, "start_col": 0, "start_line": 192 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_pre Vale.AsLowStar.Test.aesni_dom
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Vale.Lib.X64.Cpuidstdcall.va_req_Check_aesni_stdcall", "Vale.Interop.Assumptions.win", "Prims.prop" ]
[]
false
false
false
true
false
let aesni_pre:VSig.vale_pre aesni_dom =
fun (c: V.va_code) (va_s0: V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.aesni_post
val aesni_post:VSig.vale_post aesni_dom
val aesni_post:VSig.vale_post aesni_dom
let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 203, "start_col": 0, "start_line": 198 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_post Vale.AsLowStar.Test.aesni_dom
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "Vale.Lib.X64.Cpuidstdcall.va_ens_Check_aesni_stdcall", "Vale.Interop.Assumptions.win", "Prims.prop" ]
[]
false
false
false
true
false
let aesni_post:VSig.vale_post aesni_dom =
fun (c: V.va_code) (va_s0: V.va_state) (va_s1: V.va_state) (f: V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.code_ta
val code_ta : Vale.X64.Decls.va_code
let code_ta = TA.va_code_Test IA.win
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 375, "start_col": 0, "start_line": 375 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *) [@__reduce__] let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) [@__reduce__] let ta_post : VSig.vale_post ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let ta_lemma' (code:V.va_code) (_win:bool) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires ta_pre code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ ta_post code arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg0) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg1) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg2) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg3) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg4) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg5) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg6) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer arg7) /\ ME.modifies ME.loc_none (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1))) = let va_s1, f = TA.va_lemma_Test code va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) in va_s1, f (* Prove that vm_lemma' has the required type *) let ta_lemma = as_t #(VSig.vale_sig_stdcall ta_pre ta_post) ta_lemma'
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Vale.Test.X64.Args.va_code_Test", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
false
let code_ta =
TA.va_code_Test IA.win
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_aesni_normal_t
val lowstar_aesni_normal_t : Vale.Interop.Base.normal Vale.AsLowStar.Test.lowstar_aesni_t
let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 255, "start_col": 0, "start_line": 254 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.normal Vale.AsLowStar.Test.lowstar_aesni_t
Prims.Tot
[ "total" ]
[]
[ "Vale.AsLowStar.Test.as_normal_t", "Vale.AsLowStar.Test.lowstar_aesni_t", "Vale.AsLowStar.Test.lowstar_aesni" ]
[]
false
false
false
true
false
let lowstar_aesni_normal_t =
as_normal_t #lowstar_aesni_t lowstar_aesni
false
Steel.Effect.M.fst
Steel.Effect.M.return
val return (a: Type) (x: a) (p: (a -> slprop)) (post: ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post
val return (a: Type) (x: a) (p: (a -> slprop)) (post: ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post
let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 60, "start_col": 0, "start_line": 58 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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 -> p: (_: a -> Steel.Memory.slprop) -> post: Steel.Effect.M.ens_t (p x) a p -> Steel.Effect.M.repr a (p x) p (Steel.Semantics.Hoare.MST.return_lpre x post) post
Prims.Tot
[ "total" ]
[]
[ "Steel.Memory.slprop", "Steel.Effect.M.ens_t", "Steel.Semantics.Hoare.MST.Ret", "Steel.Semantics.Instantiate.state", "Steel.Effect.M.repr", "Steel.Semantics.Hoare.MST.return_lpre" ]
[]
false
false
false
false
false
let return (a: Type) (x: a) (p: (a -> slprop)) (post: ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post =
Sem.Ret p x post
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.ta_pre
val ta_pre:VSig.vale_pre ta_dom
val ta_pre:VSig.vale_pre ta_dom
let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7)
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 300, "start_col": 0, "start_line": 281 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_pre Vale.AsLowStar.Test.ta_dom
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.ib64", "Vale.X64.Decls.va_state", "Vale.Test.X64.Args.va_req_Test", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Prims.prop" ]
[]
false
false
false
true
false
let ta_pre:VSig.vale_pre ta_dom =
fun (c: V.va_code) (arg0: ib64) (arg1: ib64) (arg2: ib64) (arg3: ib64) (arg4: ib64) (arg5: ib64) (arg6: ib64) (arg7: ib64) (va_s0: V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7)
false
Steel.Effect.M.fst
Steel.Effect.M.frame
val frame (a: Type) (pre: pre_t) (post: post_t a) (req: req_t pre) (ens: ens_t pre a post) (f: repr a pre post req ens) (frame: slprop) (f_frame: Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> (post x) `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame)
val frame (a: Type) (pre: pre_t) (post: post_t a) (req: req_t pre) (ens: ens_t pre a post) (f: repr a pre post req ens) (frame: slprop) (f_frame: Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> (post x) `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame)
let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 27, "end_line": 100, "start_col": 0, "start_line": 92 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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 -> pre: Steel.Effect.M.pre_t -> post: Steel.Effect.M.post_t a -> req: Steel.Effect.M.req_t pre -> ens: Steel.Effect.M.ens_t pre a post -> f: Steel.Effect.M.repr a pre post req ens -> frame: Steel.Memory.slprop -> f_frame: Steel.Semantics.Hoare.MST.fp_prop frame -> Steel.Effect.M.repr a (Steel.Memory.star pre frame) (fun x -> Steel.Memory.star (post x) frame) (Steel.Semantics.Hoare.MST.frame_lpre req f_frame) (Steel.Semantics.Hoare.MST.frame_lpost req ens f_frame)
Prims.Tot
[ "total" ]
[]
[ "Steel.Effect.M.pre_t", "Steel.Effect.M.post_t", "Steel.Effect.M.req_t", "Steel.Effect.M.ens_t", "Steel.Effect.M.repr", "Steel.Memory.slprop", "Steel.Semantics.Hoare.MST.fp_prop", "Steel.Semantics.Instantiate.state", "Steel.Semantics.Hoare.MST.Frame", "Steel.Memory.star", "Steel.Semantics.Hoare.MST.frame_lpre", "Steel.Semantics.Hoare.MST.frame_lpost" ]
[]
false
false
false
false
false
let frame (a: Type) (pre: pre_t) (post: post_t a) (req: req_t pre) (ens: ens_t pre a post) (f: repr a pre post req ens) (frame: slprop) (f_frame: Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> (post x) `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) =
Sem.Frame f frame f_frame
false
Steel.Effect.M.fst
Steel.Effect.M.lift_req_x
val lift_req_x (#a: Type u#a) (#pre: (a -> slprop)) (req: (x: a -> req_t (pre x))) (x: U.raise_t u#a u#b a) : req_t ((lift_post pre) x)
val lift_req_x (#a: Type u#a) (#pre: (a -> slprop)) (req: (x: a -> req_t (pre x))) (x: U.raise_t u#a u#b a) : req_t ((lift_post pre) x)
let lift_req_x (#a:Type u#a) (#pre:a -> slprop) (req:(x:a -> req_t (pre x))) : x:U.raise_t u#a u#b a -> req_t ((lift_post pre) x) = fun x -> req (U.downgrade_val x)
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 194, "start_col": 0, "start_line": 192 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame (* * However, the effect defined this way is not immediately usable from F* * * To see the issue, consider again the `bind` combinator we defined above with * explicit universe annotations: *) let bind_explicit_univs (a:Type u#a) (b:Type u#a) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g (* * In the combinator, both the computation return types are in the same universe, * and the combinator itself is polymorphic in that single universe * * However, composing computations whose result types are in different universes * is useful. For example, composition of a computation returning an existential * (p:Type0 & x:int{p}) that lives in u#1 with a continuation that projects and returns * the int that lives in u#0. * * Hence, as with other F* effects, we would like to support a bind that is doubly * polymorphic in the result type of both the computations, e.g. something like * * let bind_double_univs (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) b pre_f post_g * (Sem.bind_lpre req_f ens_f req_g) * (Sem.bind_lpost req_f ens_f ens_g) = ... * * But F*, like Lean and Agda, and unlike Coq, lacks cumulativity of universes. * So the result type (repr u#(max a b) b ...) is not well-formed, since b has * universe u#b and not u#(max a b) * * We could explicitly lift the universes to get the following type: * * let bind_double_univs_raise (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) (raise_t b) ... * * (In the file below, we sketch this in actual code.) * * But this results in other complications: * 1. The user programs now have to explicitly eliminate raise_t (by downgrading) * 2. F* effect system will reject this bind definition, since it is unaware of the * universe lifting * * To get around this, we chose a different, more restrictive representation for the * Steel effect in Steel.Effect.fst. That definition is suitably doubly universe * polymorphic, at the expense of hiding the structure of the computation trees * needed for a full fidelity interleaving semantics. * * Please see that file for further discussions on the limitations of that * representation. * * In the meantime, we are working on adding universe cumulativity to F* that will * allow bind_double_univs to be defined and then we can switch to the action trees * based representation for the effect. *) /// Sketch for supporting different universes in the two computations module U = FStar.Universe module T = FStar.Tactics /// Auxiliary functions for lifting post, ens, etc. let lift_post #a (post:post_t u#a a) : post_t u#(max a b) (U.raise_t a) = fun x -> post (U.downgrade_val x) let lift_ens #pre #a #post (ens:ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post) = fun m0 x m1 -> ens m0 (U.downgrade_val x) m1
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
req: (x: a -> Steel.Effect.M.req_t (pre x)) -> x: FStar.Universe.raise_t a -> Steel.Effect.M.req_t (Steel.Effect.M.lift_post pre x)
Prims.Tot
[ "total" ]
[]
[ "Steel.Memory.slprop", "Steel.Effect.M.req_t", "FStar.Universe.raise_t", "FStar.Universe.downgrade_val", "Steel.Effect.M.lift_post" ]
[]
false
false
false
false
false
let lift_req_x (#a: Type u#a) (#pre: (a -> slprop)) (req: (x: a -> req_t (pre x))) (x: U.raise_t u#a u#b a) : req_t ((lift_post pre) x) =
fun x -> req (U.downgrade_val x)
false
Steel.Effect.M.fst
Steel.Effect.M.bind_explicit_univs
val bind_explicit_univs (a b: Type u#a) (pre_f: pre_t) (post_f: post_t a) (req_f: req_t pre_f) (ens_f: ens_t pre_f a post_f) (post_g: post_t b) (req_g: (x: a -> req_t (post_f x))) (ens_g: (x: a -> ens_t (post_f x) b post_g)) (f: repr a pre_f post_f req_f ens_f) (g: (x: a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g)
val bind_explicit_univs (a b: Type u#a) (pre_f: pre_t) (post_f: post_t a) (req_f: req_t pre_f) (ens_f: ens_t pre_f a post_f) (post_g: post_t b) (req_g: (x: a -> req_t (post_f x))) (ens_g: (x: a -> ens_t (post_f x) b post_g)) (f: repr a pre_f post_f req_f ens_f) (g: (x: a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g)
let bind_explicit_univs (a:Type u#a) (b:Type u#a) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 14, "end_line": 116, "start_col": 0, "start_line": 109 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame (* * However, the effect defined this way is not immediately usable from F* * * To see the issue, consider again the `bind` combinator we defined above with * explicit universe annotations:
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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 -> pre_f: Steel.Effect.M.pre_t -> post_f: Steel.Effect.M.post_t a -> req_f: Steel.Effect.M.req_t pre_f -> ens_f: Steel.Effect.M.ens_t pre_f a post_f -> post_g: Steel.Effect.M.post_t b -> req_g: (x: a -> Steel.Effect.M.req_t (post_f x)) -> ens_g: (x: a -> Steel.Effect.M.ens_t (post_f x) b post_g) -> f: Steel.Effect.M.repr a pre_f post_f req_f ens_f -> g: (x: a -> Steel.Effect.M.repr b (post_f x) post_g (req_g x) (ens_g x)) -> Steel.Effect.M.repr b pre_f post_g (Steel.Semantics.Hoare.MST.bind_lpre req_f ens_f req_g) (Steel.Semantics.Hoare.MST.bind_lpost req_f ens_f ens_g)
Prims.Tot
[ "total" ]
[]
[ "Steel.Effect.M.pre_t", "Steel.Effect.M.post_t", "Steel.Effect.M.req_t", "Steel.Effect.M.ens_t", "Steel.Effect.M.repr", "Steel.Semantics.Hoare.MST.Bind", "Steel.Semantics.Instantiate.state", "Steel.Semantics.Hoare.MST.bind_lpre", "Steel.Semantics.Hoare.MST.bind_lpost" ]
[]
false
false
false
false
false
let bind_explicit_univs (a b: Type u#a) (pre_f: pre_t) (post_f: post_t a) (req_f: req_t pre_f) (ens_f: ens_t pre_f a post_f) (post_g: post_t b) (req_g: (x: a -> req_t (post_f x))) (ens_g: (x: a -> ens_t (post_f x) b post_g)) (f: repr a pre_f post_f req_f ens_f) (g: (x: a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) =
Sem.Bind f g
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.ta_post
val ta_post:VSig.vale_post ta_dom
val ta_post:VSig.vale_post ta_dom
let ta_post : VSig.vale_post ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 325, "start_col": 0, "start_line": 303 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *) [@__reduce__] let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) (* And here's the memcpy wrapper itself *) let lowstar_Memcpy : lowstar_Memcpy_t = IX64.wrap_weak_stdcall code_Memcpy vm_dom (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win)) let lowstar_Memcpy_normal_t //: normal lowstar_Memcpy_t = as_normal_t #lowstar_Memcpy_t lowstar_Memcpy module B = LowStar.Buffer module IB = LowStar.ImmutableBuffer module MB = LowStar.Monotonic.Buffer open FStar.HyperStack.ST module M = Vale.X64.Memory let test (x:b64) = assert (V.buffer_length (as_vale_buffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_buffer x) == B.length x / 8) let itest (x:ib64) = assert (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n TUInt8) / view_n TUInt64); assert (V.buffer_length (as_vale_immbuffer x) == B.length x / 8) module T = FStar.Tactics #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" module LBV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down #push-options "--ext compat:normalizer_memo_ignore_cfg" let memcpy_Test (dst:B.buffer UInt8.t{B.length dst % 8 == 0}) (src:IB.ibuffer UInt8.t{B.length src % 8 == 0}) : Stack UInt64.t (requires fun h0 -> B.live h0 dst /\ B.live h0 src /\ B.disjoint dst src /\ B.length dst == 16 /\ B.length src == 16) (ensures fun h0 _ h1 -> B.modifies (B.loc_buffer dst) h0 h1 /\ B.live h1 src /\ B.live h1 dst) // B.as_seq h1 dst == B.as_seq h1 src) // by (T.dump "A") (* in case you want to look at the VC *) = IB.inhabited_immutable_buffer_is_distinct_from_buffer (UInt8.uint_to_t 0) src dst; let (x, _) = lowstar_Memcpy_normal_t dst src () in //This is a call to the interop wrapper let h1 = get () in // let v = Vale.Interop.Views.up_view64 in // assert (DV.length_eq (get_downview dst); // DV.length_eq (get_downview src); // Seq.equal (LBV.as_seq h1 (LBV.mk_buffer (get_downview dst) v)) // (LBV.as_seq h1 (LBV.mk_buffer (get_downview src) v))); // lbv_as_seq_eq dst src Vale.Interop.Views.up_view64 h1; //And a lemma to rephrase the Vale postcondition x //with equalities of buffer views //back to equalities of buffers #pop-options module VC = Vale.Lib.X64.Cpuidstdcall [@__reduce__] let empty_list #a : l:list a {List.length l = 0} = [] [@__reduce__] let aesni_dom : IX64.arity_ok_stdcall td = [] (* Need to rearrange the order of arguments *) [@__reduce__] let aesni_pre : VSig.vale_pre aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) -> VC.va_req_Check_aesni_stdcall c va_s0 IA.win [@__reduce__] let aesni_post : VSig.vale_post aesni_dom = fun (c:V.va_code) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VC.va_ens_Check_aesni_stdcall c va_s0 IA.win va_s1 f [@__reduce__] let with_len (l:list 'a) : Pure (list 'a) (requires True) (ensures fun m -> m==l /\ List.length m == normalize_term (List.length l)) = l #set-options "--max_fuel 0 --max_ifuel 1 --z3rlimit_factor 2" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let aesni_lemma' (code:V.va_code) (_win:bool) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires aesni_pre code va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ aesni_post code va_s0 va_s1 f)) = VC.va_lemma_Check_aesni_stdcall code va_s0 IA.win #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit_factor 2" (* Prove that vm_lemma' has the required type *) let aesni_lemma = as_t #(VSig.vale_sig_stdcall aesni_pre aesni_post) aesni_lemma' let code_aesni = VC.va_code_Check_aesni_stdcall IA.win (* Here's the type expected for the check_aesni wrapper *) [@__reduce__] let lowstar_aesni_t = IX64.as_lowstar_sig_t_weak_stdcall (coerce code_aesni) aesni_dom empty_list _ _ (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) (* And here's the check_aesni wrapper itself *) let lowstar_aesni : lowstar_aesni_t = IX64.wrap_weak_stdcall (coerce code_aesni) aesni_dom (W.mk_prediction code_aesni aesni_dom [] (aesni_lemma code_aesni IA.win)) let lowstar_aesni_normal_t //: normal lowstar_aesni_t = as_normal_t #lowstar_aesni_t lowstar_aesni open Vale.X64.CPU_Features_s #set-options "--print_full_names" let aesni_Test () : Stack UInt64.t (requires fun h0 -> True) (ensures fun h0 ret_val h1 -> (UInt64.v ret_val) =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) // by (T.dump "A") (* in case you want to look at the VC *) = let (x, _) = lowstar_aesni_normal_t () in //This is a call to the interop wrapper x module TA = Vale.Test.X64.Args [@__reduce__] let (ta_dom:list td{List.length ta_dom <= 20}) = let y = [t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm; t64_imm] in assert_norm (List.length y = 8); y (* Need to rearrange the order of arguments *) [@__reduce__] let ta_pre : VSig.vale_pre ta_dom = fun (c:V.va_code) (arg0:ib64) (arg1:ib64) (arg2:ib64) (arg3:ib64) (arg4:ib64) (arg5:ib64) (arg6:ib64) (arg7:ib64) (va_s0:V.va_state) -> TA.va_req_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.Test.X64.Args", "short_module": "TA" }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.X64.Cpuidstdcall", "short_module": "VC" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "LBV" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "M" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 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": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.AsLowStar.ValeSig.vale_post Vale.AsLowStar.Test.ta_dom
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.AsLowStar.Test.ib64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "Vale.Test.X64.Args.va_ens_Test", "Vale.Interop.Assumptions.win", "Vale.X64.MemoryAdapters.as_vale_immbuffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt64", "Prims.prop" ]
[]
false
false
false
true
false
let ta_post:VSig.vale_post ta_dom =
fun (c: V.va_code) (arg0: ib64) (arg1: ib64) (arg2: ib64) (arg3: ib64) (arg4: ib64) (arg5: ib64) (arg6: ib64) (arg7: ib64) (va_s0: V.va_state) (va_s1: V.va_state) (f: V.va_fuel) -> TA.va_ens_Test c va_s0 IA.win (as_vale_immbuffer arg0) (as_vale_immbuffer arg1) (as_vale_immbuffer arg2) (as_vale_immbuffer arg3) (as_vale_immbuffer arg4) (as_vale_immbuffer arg5) (as_vale_immbuffer arg6) (as_vale_immbuffer arg7) va_s1 f
false
Steel.Effect.M.fst
Steel.Effect.M.lift_post
val lift_post (#a: _) (post: post_t u#a a) : post_t u#(max a b) (U.raise_t a)
val lift_post (#a: _) (post: post_t u#a a) : post_t u#(max a b) (U.raise_t a)
let lift_post #a (post:post_t u#a a) : post_t u#(max a b) (U.raise_t a) = fun x -> post (U.downgrade_val x)
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 186, "start_col": 0, "start_line": 184 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame (* * However, the effect defined this way is not immediately usable from F* * * To see the issue, consider again the `bind` combinator we defined above with * explicit universe annotations: *) let bind_explicit_univs (a:Type u#a) (b:Type u#a) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g (* * In the combinator, both the computation return types are in the same universe, * and the combinator itself is polymorphic in that single universe * * However, composing computations whose result types are in different universes * is useful. For example, composition of a computation returning an existential * (p:Type0 & x:int{p}) that lives in u#1 with a continuation that projects and returns * the int that lives in u#0. * * Hence, as with other F* effects, we would like to support a bind that is doubly * polymorphic in the result type of both the computations, e.g. something like * * let bind_double_univs (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) b pre_f post_g * (Sem.bind_lpre req_f ens_f req_g) * (Sem.bind_lpost req_f ens_f ens_g) = ... * * But F*, like Lean and Agda, and unlike Coq, lacks cumulativity of universes. * So the result type (repr u#(max a b) b ...) is not well-formed, since b has * universe u#b and not u#(max a b) * * We could explicitly lift the universes to get the following type: * * let bind_double_univs_raise (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) (raise_t b) ... * * (In the file below, we sketch this in actual code.) * * But this results in other complications: * 1. The user programs now have to explicitly eliminate raise_t (by downgrading) * 2. F* effect system will reject this bind definition, since it is unaware of the * universe lifting * * To get around this, we chose a different, more restrictive representation for the * Steel effect in Steel.Effect.fst. That definition is suitably doubly universe * polymorphic, at the expense of hiding the structure of the computation trees * needed for a full fidelity interleaving semantics. * * Please see that file for further discussions on the limitations of that * representation. * * In the meantime, we are working on adding universe cumulativity to F* that will * allow bind_double_univs to be defined and then we can switch to the action trees * based representation for the effect. *) /// Sketch for supporting different universes in the two computations module U = FStar.Universe module T = FStar.Tactics /// Auxiliary functions for lifting post, ens, etc.
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
post: Steel.Effect.M.post_t a -> Steel.Effect.M.post_t (FStar.Universe.raise_t a)
Prims.Tot
[ "total" ]
[]
[ "Steel.Effect.M.post_t", "FStar.Universe.raise_t", "FStar.Universe.downgrade_val", "Steel.Memory.slprop" ]
[]
false
false
false
true
false
let lift_post #a (post: post_t u#a a) : post_t u#(max a b) (U.raise_t a) =
fun x -> post (U.downgrade_val x)
false
Steel.Effect.M.fst
Steel.Effect.M.lift_m_x
val lift_m_x (#a: Type u#a) (#pre: (a -> slprop)) (#b: Type u#b) (#post: post_t b) (#req: (x: a -> req_t (pre x))) (#ens: (x: a -> ens_t (pre x) b post)) (f: (x: a -> repr u#b b (pre x) post (req x) (ens x))) (x: U.raise_t u#a u#b a) : repr u#(max a b) (U.raise_t b) ((lift_post pre) x) (lift_post post) ((lift_req_x req) x) ((lift_ens_x ens) x)
val lift_m_x (#a: Type u#a) (#pre: (a -> slprop)) (#b: Type u#b) (#post: post_t b) (#req: (x: a -> req_t (pre x))) (#ens: (x: a -> ens_t (pre x) b post)) (f: (x: a -> repr u#b b (pre x) post (req x) (ens x))) (x: U.raise_t u#a u#b a) : repr u#(max a b) (U.raise_t b) ((lift_post pre) x) (lift_post post) ((lift_req_x req) x) ((lift_ens_x ens) x)
let lift_m_x (#a:Type u#a) (#pre:a -> slprop) (#b:Type u#b) (#post:post_t b) (#req:(x:a -> req_t (pre x))) (#ens:(x:a -> ens_t (pre x) b post)) (f:(x:a -> repr u#b b (pre x) post (req x) (ens x))) : x:U.raise_t u#a u#b a -> repr u#(max a b) (U.raise_t b) ((lift_post pre) x) (lift_post post) ((lift_req_x req) x) ((lift_ens_x ens) x) = fun x -> lift_m (f (U.downgrade_val x))
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 242, "start_col": 0, "start_line": 233 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame (* * However, the effect defined this way is not immediately usable from F* * * To see the issue, consider again the `bind` combinator we defined above with * explicit universe annotations: *) let bind_explicit_univs (a:Type u#a) (b:Type u#a) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g (* * In the combinator, both the computation return types are in the same universe, * and the combinator itself is polymorphic in that single universe * * However, composing computations whose result types are in different universes * is useful. For example, composition of a computation returning an existential * (p:Type0 & x:int{p}) that lives in u#1 with a continuation that projects and returns * the int that lives in u#0. * * Hence, as with other F* effects, we would like to support a bind that is doubly * polymorphic in the result type of both the computations, e.g. something like * * let bind_double_univs (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) b pre_f post_g * (Sem.bind_lpre req_f ens_f req_g) * (Sem.bind_lpost req_f ens_f ens_g) = ... * * But F*, like Lean and Agda, and unlike Coq, lacks cumulativity of universes. * So the result type (repr u#(max a b) b ...) is not well-formed, since b has * universe u#b and not u#(max a b) * * We could explicitly lift the universes to get the following type: * * let bind_double_univs_raise (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) (raise_t b) ... * * (In the file below, we sketch this in actual code.) * * But this results in other complications: * 1. The user programs now have to explicitly eliminate raise_t (by downgrading) * 2. F* effect system will reject this bind definition, since it is unaware of the * universe lifting * * To get around this, we chose a different, more restrictive representation for the * Steel effect in Steel.Effect.fst. That definition is suitably doubly universe * polymorphic, at the expense of hiding the structure of the computation trees * needed for a full fidelity interleaving semantics. * * Please see that file for further discussions on the limitations of that * representation. * * In the meantime, we are working on adding universe cumulativity to F* that will * allow bind_double_univs to be defined and then we can switch to the action trees * based representation for the effect. *) /// Sketch for supporting different universes in the two computations module U = FStar.Universe module T = FStar.Tactics /// Auxiliary functions for lifting post, ens, etc. let lift_post #a (post:post_t u#a a) : post_t u#(max a b) (U.raise_t a) = fun x -> post (U.downgrade_val x) let lift_ens #pre #a #post (ens:ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post) = fun m0 x m1 -> ens m0 (U.downgrade_val x) m1 let lift_req_x (#a:Type u#a) (#pre:a -> slprop) (req:(x:a -> req_t (pre x))) : x:U.raise_t u#a u#b a -> req_t ((lift_post pre) x) = fun x -> req (U.downgrade_val x) let lift_ens_x (#a:Type u#a) (#pre:a -> slprop) (#b:Type u#b) (#post:_) (ens:(x:a -> ens_t u#b (pre x) b post)) : x:U.raise_t u#a u#b a -> ens_t u#(max a b) ((lift_post pre) x) (U.raise_t b) (lift_post post) = fun x -> (fun m0 y m1 -> (ens (U.downgrade_val x)) m0 (U.downgrade_val y) m1) /// Lifting `m` terms, implementing only the Ret case //NS, AR: This is failure since the patch to 2635 //It fails because: // we got the problem ?u:t = e <: t, i.e. ascription on RHS, // but when solving we removed the ascription, so we solved ?u = e // and then retypechecking e did not succeed //Some possibilities for restoring this: // 1. Patch Rel to retain ascriptions? // 2. Maybe using PR 2482 we can do the rewrite at a weaker type and then conclude #push-options "--warn_error -296" let lift_m (#a:Type u#a) (#pre:pre_t) (#post:post_t u#a a) (#req:req_t pre) (#ens:ens_t pre a post) (f:repr u#a a pre post req ens) : repr u#(max a b) (FStar.Universe.raise_t a) pre (lift_post post) req (lift_ens ens) = match f with | Sem.Ret #_ #_ post x lpost -> assert ((Sem.return_lpre #_ #_ #(lift_post post) (U.raise_val u#a u#b x) (lift_ens lpost)) == Sem.return_lpre #_ #_ #post x lpost) by T.(tadmit()) ; // T.(norm [delta_only [`%Sem.return_lpre; `%lift_post; `%lift_ens]]; // FStar.Tactics.Derived.l_to_r [`U.downgrade_val_raise_val ]; // trefl()); Sem.Ret (lift_post post) (U.raise_val x) (lift_ens lpost) | _ -> admit () #pop-options
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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: (x: a -> Steel.Effect.M.repr b (pre x) post (req x) (ens x)) -> x: FStar.Universe.raise_t a -> Steel.Effect.M.repr (FStar.Universe.raise_t b) (Steel.Effect.M.lift_post pre x) (Steel.Effect.M.lift_post post) (Steel.Effect.M.lift_req_x req x) (Steel.Effect.M.lift_ens_x ens x)
Prims.Tot
[ "total" ]
[]
[ "Steel.Memory.slprop", "Steel.Effect.M.post_t", "Steel.Effect.M.req_t", "Steel.Effect.M.ens_t", "Steel.Effect.M.repr", "FStar.Universe.raise_t", "Steel.Effect.M.lift_m", "FStar.Universe.downgrade_val", "Steel.Effect.M.lift_post", "Steel.Effect.M.lift_req_x", "Steel.Effect.M.lift_ens_x" ]
[]
false
false
false
false
false
let lift_m_x (#a: Type u#a) (#pre: (a -> slprop)) (#b: Type u#b) (#post: post_t b) (#req: (x: a -> req_t (pre x))) (#ens: (x: a -> ens_t (pre x) b post)) (f: (x: a -> repr u#b b (pre x) post (req x) (ens x))) (x: U.raise_t u#a u#b a) : repr u#(max a b) (U.raise_t b) ((lift_post pre) x) (lift_post post) ((lift_req_x req) x) ((lift_ens_x ens) x) =
fun x -> lift_m (f (U.downgrade_val x))
false
Steel.Effect.M.fst
Steel.Effect.M.bind_lift
val bind_lift (a: Type u#a) (b: Type u#b) (pre_f: pre_t) (post_f: post_t a) (req_f: req_t pre_f) (ens_f: ens_t pre_f a post_f) (post_g: post_t b) (req_g: (x: a -> req_t (post_f x))) (ens_g: (x: a -> ens_t (post_f x) b post_g)) (f: repr a pre_f post_f req_f ens_f) (g: (x: a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#(max a b) (U.raise_t b) pre_f (lift_post post_g) (Sem.bind_lpre req_f (lift_ens ens_f) (lift_req_x req_g)) (Sem.bind_lpost u#(max a b) u#(max a b) #state #(U.raise_t u#a u#b a) #pre_f #(lift_post post_f) req_f (lift_ens ens_f) #(U.raise_t b) #(lift_post post_g) (lift_ens_x ens_g))
val bind_lift (a: Type u#a) (b: Type u#b) (pre_f: pre_t) (post_f: post_t a) (req_f: req_t pre_f) (ens_f: ens_t pre_f a post_f) (post_g: post_t b) (req_g: (x: a -> req_t (post_f x))) (ens_g: (x: a -> ens_t (post_f x) b post_g)) (f: repr a pre_f post_f req_f ens_f) (g: (x: a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#(max a b) (U.raise_t b) pre_f (lift_post post_g) (Sem.bind_lpre req_f (lift_ens ens_f) (lift_req_x req_g)) (Sem.bind_lpost u#(max a b) u#(max a b) #state #(U.raise_t u#a u#b a) #pre_f #(lift_post post_f) req_f (lift_ens ens_f) #(U.raise_t b) #(lift_post post_g) (lift_ens_x ens_g))
let bind_lift (a:Type u#a) (b:Type u#b) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#(max a b) (U.raise_t b) pre_f (lift_post post_g) (Sem.bind_lpre req_f (lift_ens ens_f) (lift_req_x req_g)) (Sem.bind_lpost u#(max a b) u#(max a b) #state #(U.raise_t u#a u#b a) #pre_f #(lift_post post_f) req_f (lift_ens ens_f) #(U.raise_t b) #(lift_post post_g) (lift_ens_x ens_g)) = let f = lift_m f in let g = lift_m_x g in Sem.Bind f g
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 14, "end_line": 265, "start_col": 0, "start_line": 247 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame (* * However, the effect defined this way is not immediately usable from F* * * To see the issue, consider again the `bind` combinator we defined above with * explicit universe annotations: *) let bind_explicit_univs (a:Type u#a) (b:Type u#a) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g (* * In the combinator, both the computation return types are in the same universe, * and the combinator itself is polymorphic in that single universe * * However, composing computations whose result types are in different universes * is useful. For example, composition of a computation returning an existential * (p:Type0 & x:int{p}) that lives in u#1 with a continuation that projects and returns * the int that lives in u#0. * * Hence, as with other F* effects, we would like to support a bind that is doubly * polymorphic in the result type of both the computations, e.g. something like * * let bind_double_univs (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) b pre_f post_g * (Sem.bind_lpre req_f ens_f req_g) * (Sem.bind_lpost req_f ens_f ens_g) = ... * * But F*, like Lean and Agda, and unlike Coq, lacks cumulativity of universes. * So the result type (repr u#(max a b) b ...) is not well-formed, since b has * universe u#b and not u#(max a b) * * We could explicitly lift the universes to get the following type: * * let bind_double_univs_raise (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) (raise_t b) ... * * (In the file below, we sketch this in actual code.) * * But this results in other complications: * 1. The user programs now have to explicitly eliminate raise_t (by downgrading) * 2. F* effect system will reject this bind definition, since it is unaware of the * universe lifting * * To get around this, we chose a different, more restrictive representation for the * Steel effect in Steel.Effect.fst. That definition is suitably doubly universe * polymorphic, at the expense of hiding the structure of the computation trees * needed for a full fidelity interleaving semantics. * * Please see that file for further discussions on the limitations of that * representation. * * In the meantime, we are working on adding universe cumulativity to F* that will * allow bind_double_univs to be defined and then we can switch to the action trees * based representation for the effect. *) /// Sketch for supporting different universes in the two computations module U = FStar.Universe module T = FStar.Tactics /// Auxiliary functions for lifting post, ens, etc. let lift_post #a (post:post_t u#a a) : post_t u#(max a b) (U.raise_t a) = fun x -> post (U.downgrade_val x) let lift_ens #pre #a #post (ens:ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post) = fun m0 x m1 -> ens m0 (U.downgrade_val x) m1 let lift_req_x (#a:Type u#a) (#pre:a -> slprop) (req:(x:a -> req_t (pre x))) : x:U.raise_t u#a u#b a -> req_t ((lift_post pre) x) = fun x -> req (U.downgrade_val x) let lift_ens_x (#a:Type u#a) (#pre:a -> slprop) (#b:Type u#b) (#post:_) (ens:(x:a -> ens_t u#b (pre x) b post)) : x:U.raise_t u#a u#b a -> ens_t u#(max a b) ((lift_post pre) x) (U.raise_t b) (lift_post post) = fun x -> (fun m0 y m1 -> (ens (U.downgrade_val x)) m0 (U.downgrade_val y) m1) /// Lifting `m` terms, implementing only the Ret case //NS, AR: This is failure since the patch to 2635 //It fails because: // we got the problem ?u:t = e <: t, i.e. ascription on RHS, // but when solving we removed the ascription, so we solved ?u = e // and then retypechecking e did not succeed //Some possibilities for restoring this: // 1. Patch Rel to retain ascriptions? // 2. Maybe using PR 2482 we can do the rewrite at a weaker type and then conclude #push-options "--warn_error -296" let lift_m (#a:Type u#a) (#pre:pre_t) (#post:post_t u#a a) (#req:req_t pre) (#ens:ens_t pre a post) (f:repr u#a a pre post req ens) : repr u#(max a b) (FStar.Universe.raise_t a) pre (lift_post post) req (lift_ens ens) = match f with | Sem.Ret #_ #_ post x lpost -> assert ((Sem.return_lpre #_ #_ #(lift_post post) (U.raise_val u#a u#b x) (lift_ens lpost)) == Sem.return_lpre #_ #_ #post x lpost) by T.(tadmit()) ; // T.(norm [delta_only [`%Sem.return_lpre; `%lift_post; `%lift_ens]]; // FStar.Tactics.Derived.l_to_r [`U.downgrade_val_raise_val ]; // trefl()); Sem.Ret (lift_post post) (U.raise_val x) (lift_ens lpost) | _ -> admit () #pop-options let lift_m_x (#a:Type u#a) (#pre:a -> slprop) (#b:Type u#b) (#post:post_t b) (#req:(x:a -> req_t (pre x))) (#ens:(x:a -> ens_t (pre x) b post)) (f:(x:a -> repr u#b b (pre x) post (req x) (ens x))) : x:U.raise_t u#a u#b a -> repr u#(max a b) (U.raise_t b) ((lift_post pre) x) (lift_post post) ((lift_req_x req) x) ((lift_ens_x ens) x) = fun x -> lift_m (f (U.downgrade_val x)) /// Finally a lifted bind
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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 -> pre_f: Steel.Effect.M.pre_t -> post_f: Steel.Effect.M.post_t a -> req_f: Steel.Effect.M.req_t pre_f -> ens_f: Steel.Effect.M.ens_t pre_f a post_f -> post_g: Steel.Effect.M.post_t b -> req_g: (x: a -> Steel.Effect.M.req_t (post_f x)) -> ens_g: (x: a -> Steel.Effect.M.ens_t (post_f x) b post_g) -> f: Steel.Effect.M.repr a pre_f post_f req_f ens_f -> g: (x: a -> Steel.Effect.M.repr b (post_f x) post_g (req_g x) (ens_g x)) -> Steel.Effect.M.repr (FStar.Universe.raise_t b) pre_f (Steel.Effect.M.lift_post post_g) (Steel.Semantics.Hoare.MST.bind_lpre req_f (Steel.Effect.M.lift_ens ens_f) (Steel.Effect.M.lift_req_x req_g)) (Steel.Semantics.Hoare.MST.bind_lpost req_f (Steel.Effect.M.lift_ens ens_f) (Steel.Effect.M.lift_ens_x ens_g))
Prims.Tot
[ "total" ]
[]
[ "Steel.Effect.M.pre_t", "Steel.Effect.M.post_t", "Steel.Effect.M.req_t", "Steel.Effect.M.ens_t", "Steel.Effect.M.repr", "Steel.Semantics.Hoare.MST.Bind", "Steel.Semantics.Instantiate.state", "FStar.Universe.raise_t", "Steel.Effect.M.lift_post", "Steel.Effect.M.lift_ens", "Steel.Effect.M.lift_req_x", "Steel.Effect.M.lift_ens_x", "Steel.Effect.M.lift_m_x", "Steel.Effect.M.lift_m", "Steel.Semantics.Hoare.MST.bind_lpre", "Steel.Semantics.Hoare.MST.bind_lpost" ]
[]
false
false
false
false
false
let bind_lift (a: Type u#a) (b: Type u#b) (pre_f: pre_t) (post_f: post_t a) (req_f: req_t pre_f) (ens_f: ens_t pre_f a post_f) (post_g: post_t b) (req_g: (x: a -> req_t (post_f x))) (ens_g: (x: a -> ens_t (post_f x) b post_g)) (f: repr a pre_f post_f req_f ens_f) (g: (x: a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#(max a b) (U.raise_t b) pre_f (lift_post post_g) (Sem.bind_lpre req_f (lift_ens ens_f) (lift_req_x req_g)) (Sem.bind_lpost u#(max a b) u#(max a b) #state #(U.raise_t u#a u#b a) #pre_f #(lift_post post_f) req_f (lift_ens ens_f) #(U.raise_t b) #(lift_post post_g) (lift_ens_x ens_g)) =
let f = lift_m f in let g = lift_m_x g in Sem.Bind f g
false
Hacl.Spec.Bignum.MontArithmetic.fst
Hacl.Spec.Bignum.MontArithmetic.bn_field_get_len
val bn_field_get_len: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> BN.bn_len t
val bn_field_get_len: #t:limb_t -> k:bn_mont_ctx t{bn_mont_ctx_inv k} -> BN.bn_len t
let bn_field_get_len #t k = k.len
{ "file_name": "code/bignum/Hacl.Spec.Bignum.MontArithmetic.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 85, "start_col": 0, "start_line": 85 }
module Hacl.Spec.Bignum.MontArithmetic open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions module M = Hacl.Spec.Montgomery.Lemmas module BM = Hacl.Spec.Bignum.Montgomery module BN = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base module BL = Hacl.Spec.Bignum.Lib module BIL = Hacl.Spec.Bignum.ModInvLimb module E = Hacl.Spec.Exponentiation.Lemmas module ME = Hacl.Spec.Bignum.MontExponentiation module Euclid = FStar.Math.Euclid module BI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" ////////////////////////////////////////// val mul_zero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (x * y % n == 0 <==> (x % n == 0 \/ y % n == 0)) let mul_zero_lemma n x y = assert (0 % n = 0); if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else if y % n = 0 then Math.Lemmas.lemma_mod_mul_distr_r x y n else if x * y % n = 0 then Math.Fermat.mod_mult_congr n x 0 y else () val mul_nonzero_lemma: n:pos{Euclid.is_prime n} -> x:int -> y:int -> Lemma (requires x % n <> 0 /\ y % n <> 0) (ensures x * y % n <> 0) let mul_nonzero_lemma n x y = mul_zero_lemma n x y val from_mont_lemma_nonzero: pbits:pos -> rLen:pos -> n:pos -> mu:nat -> aM:nat -> Lemma (requires M.mont_pre pbits rLen n mu /\ 0 < aM /\ aM < n /\ Euclid.is_prime n) (ensures (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n)) let from_mont_lemma_nonzero pbits rLen n mu aM = let r = pow2 (pbits * rLen) in let d, _ = M.eea_pow2_odd (pbits * rLen) n in let a = M.from_mont pbits rLen n mu aM in M.from_mont_lemma pbits rLen n mu aM; assert (a == aM * d % n); assert (d <> 0); Math.Lemmas.small_mod aM n; assert (aM % n <> 0); let d1 = -d in assert (0 < d1 /\ d1 < n); Math.Lemmas.lemma_mod_sub_1 d1 n; assert ((-d1) % n == n - (d1 % n)); assert (d % n <> 0); mul_nonzero_lemma n aM d; assert (let a = M.from_mont pbits rLen n mu aM in 0 < a /\ a < n); // For some reason, this makes the proof instant. () ///////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.MontExponentiation.fst.checked", "Hacl.Spec.Bignum.ModInvLimb.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Math.Fermat.fsti.checked", "FStar.Math.Euclid.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.MontArithmetic.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.MontExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInvLimb", "short_module": "BIL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx t {Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv k} -> Hacl.Spec.Bignum.bn_len t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx", "Hacl.Spec.Bignum.MontArithmetic.bn_mont_ctx_inv", "Hacl.Spec.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx__item__len", "Hacl.Spec.Bignum.bn_len" ]
[]
false
false
false
false
false
let bn_field_get_len #t k =
k.len
false
LowParseWriters.LowParse.fsti
LowParseWriters.LowParse.parse_empty
val parse_empty:parser
val parse_empty:parser
let parse_empty : parser = Parser unit parse_empty'
{ "file_name": "examples/layeredeffects/LowParseWriters.LowParse.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 78, "start_col": 0, "start_line": 78 }
module LowParseWriters.LowParse module HS = FStar.HyperStack module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST type u8 : Type0 = U8.t val parser' (t: Type0) : Type u#1 inline_for_extraction noextract noeq type parser = | Parser: t: Type -> p: parser' t -> parser val valid_pos (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : GTot Type0 val valid_pos_post (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( B.live h b /\ U32.v pos <= U32.v pos' /\ U32.v pos' <= B.length b )) [SMTPat (valid_pos p h b pos pos')] val contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Ghost (Parser?.t p) (requires (valid_pos p h b pos pos')) (ensures (fun _ -> True)) val size (p: parser) (x: Parser?.t p) : GTot nat val contents_size (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( valid_pos p h b pos pos' /\ size p (contents p h b pos pos') == U32.v pos' - U32.v pos )) [SMTPat (contents p h b pos pos')] inline_for_extraction val parse_empty' : parser' unit
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.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.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParseWriters.LowParse.fsti" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
LowParseWriters.LowParse.parser
Prims.Tot
[ "total" ]
[]
[ "LowParseWriters.LowParse.Parser", "Prims.unit", "LowParseWriters.LowParse.parse_empty'" ]
[]
false
false
false
true
false
let parse_empty:parser =
Parser unit parse_empty'
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.as_normal_t
val as_normal_t (#a: Type) (x: a) : normal a
val as_normal_t (#a: Type) (x: a) : normal a
let as_normal_t (#a:Type) (x:a) : normal a = x
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 15, "start_col": 0, "start_line": 15 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> Vale.Interop.Base.normal a
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.normal" ]
[]
false
false
false
true
false
let as_normal_t (#a: Type) (x: a) : normal a =
x
false
LowParseWriters.LowParse.fsti
LowParseWriters.LowParse.parse_pair
val parse_pair (p1 p2: parser) : Tot parser
val parse_pair (p1 p2: parser) : Tot parser
let parse_pair (p1 p2: parser) : Tot parser = Parser (Parser?.t p1 & Parser?.t p2) (parse_pair' (Parser?.p p1) (Parser?.p p2))
{ "file_name": "examples/layeredeffects/LowParseWriters.LowParse.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 126, "end_line": 100, "start_col": 0, "start_line": 100 }
module LowParseWriters.LowParse module HS = FStar.HyperStack module B = LowStar.Buffer module U8 = FStar.UInt8 module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST type u8 : Type0 = U8.t val parser' (t: Type0) : Type u#1 inline_for_extraction noextract noeq type parser = | Parser: t: Type -> p: parser' t -> parser val valid_pos (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : GTot Type0 val valid_pos_post (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( B.live h b /\ U32.v pos <= U32.v pos' /\ U32.v pos' <= B.length b )) [SMTPat (valid_pos p h b pos pos')] val contents (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Ghost (Parser?.t p) (requires (valid_pos p h b pos pos')) (ensures (fun _ -> True)) val size (p: parser) (x: Parser?.t p) : GTot nat val contents_size (p: parser) (h: HS.mem) (b: B.buffer U8.t) (pos: U32.t) (pos' : U32.t) : Lemma (requires (valid_pos p h b pos pos')) (ensures ( valid_pos p h b pos pos' /\ size p (contents p h b pos pos') == U32.v pos' - U32.v pos )) [SMTPat (contents p h b pos pos')] inline_for_extraction val parse_empty' : parser' unit inline_for_extraction let parse_empty : parser = Parser unit parse_empty' val valid_parse_empty (h: HS.mem) (b: B.buffer u8) (pos: U32.t) (pos' : U32.t) : Lemma ( valid_pos parse_empty h b pos pos' <==> ( B.live h b /\ U32.v pos <= B.length b /\ U32.v pos' == U32.v pos )) [SMTPat (valid_pos parse_empty h b pos pos')] val size_parse_empty : squash (size parse_empty () == 0) inline_for_extraction val parse_pair' (#t1 #t2: Type) (p1: parser' t1) (p2: parser' t2) : Tot (parser' (t1 & t2))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.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.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParseWriters.LowParse.fsti" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "LowParseWriters", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
p1: LowParseWriters.LowParse.parser -> p2: LowParseWriters.LowParse.parser -> LowParseWriters.LowParse.parser
Prims.Tot
[ "total" ]
[]
[ "LowParseWriters.LowParse.parser", "LowParseWriters.LowParse.Parser", "FStar.Pervasives.Native.tuple2", "LowParseWriters.LowParse.__proj__Parser__item__t", "LowParseWriters.LowParse.parse_pair'", "LowParseWriters.LowParse.__proj__Parser__item__p" ]
[]
false
false
false
true
false
let parse_pair (p1 p2: parser) : Tot parser =
Parser (Parser?.t p1 & Parser?.t p2) (parse_pair' (Parser?.p p1) (Parser?.p p2))
false
Pulse.Show.fst
Pulse.Show.showable_option
[@@ FStar.Tactics.Typeclasses.tcinstance] val showable_option: a: Type -> tac_showable a -> tac_showable (option a)
[@@ FStar.Tactics.Typeclasses.tcinstance] val showable_option: a: Type -> tac_showable a -> tac_showable (option a)
instance showable_option (a:Type) (_ : tac_showable a) : tac_showable (option a) = { show = (function None -> "None" | Some v -> "Some " ^ show v); }
{ "file_name": "lib/steel/pulse/Pulse.Show.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 48, "start_col": 0, "start_line": 45 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Show open FStar.Tactics open FStar.Tactics.Typeclasses open Pulse.Typing open Pulse.Syntax.Base open Pulse.Syntax.Printer class tac_showable (a:Type) = { show : a -> Tac string; } instance _ : tac_showable string = { show = (fun s -> s); } instance _ : tac_showable unit = { show = (fun () -> "()"); } instance _ : tac_showable bool = { show = (fun b -> string_of_bool b); } instance _ : tac_showable int = { show = (fun b -> string_of_int b); }
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Printer.fsti.checked", "Pulse.Syntax.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Show.fst" }
[ { "abbrev": false, "full_module": "Pulse.Syntax.Printer", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> _: Pulse.Show.tac_showable a -> Pulse.Show.tac_showable (FStar.Pervasives.Native.option a)
Prims.Tot
[ "total" ]
[]
[ "Pulse.Show.tac_showable", "Pulse.Show.Mktac_showable", "FStar.Pervasives.Native.option", "Prims.string", "Prims.op_Hat", "Pulse.Show.show" ]
[]
false
false
false
true
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let showable_option (a: Type) (_: tac_showable a) : tac_showable (option a) =
{ show = (function | None -> "None" | Some v -> "Some " ^ show v) }
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.as_t
val as_t (#a: Type) (x: normal a) : a
val as_t (#a: Type) (x: normal a) : a
let as_t (#a:Type) (x:normal a) : a = x
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 14, "start_col": 0, "start_line": 14 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Interop.Base.normal a -> a
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.normal" ]
[]
false
false
false
true
false
let as_t (#a: Type) (x: normal a) : a =
x
false
Vale.AsLowStar.Test.fst
Vale.AsLowStar.Test.lowstar_Memcpy_t
val lowstar_Memcpy_t : Type0
let lowstar_Memcpy_t = IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.Test.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 73, "end_line": 121, "start_col": 0, "start_line": 114 }
module Vale.AsLowStar.Test open FStar.Mul open Vale.Interop.Base module ME = Vale.X64.Memory module IA = Vale.Interop.Assumptions module V = Vale.X64.Decls module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module W = Vale.AsLowStar.Wrapper module VS = Vale.X64.State module MS = Vale.X64.Machine_s (* A little utility to trigger normalization in types *) let as_t (#a:Type) (x:normal a) : a = x let as_normal_t (#a:Type) (x:a) : normal a = x //////////////////////////////////////////////////////////////////////////////// //First a little standalone, toy experiment [@__reduce__] let b64 = buf_t TUInt8 TUInt64 [@__reduce__] let ib64 = ibuf_t TUInt8 TUInt64 [@__reduce__] let t64_mod = TD_Buffer TUInt8 TUInt64 default_bq [@__reduce__] let t64_no_mod = TD_Buffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let t64_imm = TD_ImmBuffer TUInt8 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] let (dom : list td{List.length dom <= 20}) = let y = [t64_mod;t64_imm] in assert_norm (List.length y = 2); y assume val pre : VSig.vale_pre dom assume val post : VSig.vale_post dom assume val v: VSig.vale_sig_stdcall pre post assume val c: V.va_code [@__reduce__] let call_c_t = IX64.as_lowstar_sig_t_weak_stdcall c dom [] _ _ (W.mk_prediction c dom [] (v c IA.win)) let call_c : call_c_t = IX64.wrap_weak_stdcall c dom (W.mk_prediction c dom [] (v c IA.win)) let call_c_normal_t : normal call_c_t = as_normal_t #call_c_t call_c //You can ask emacs to show you the type of call_c_normal_t ... //////////////////////////////////////////////////////////////////////////////// //Now memcpy module VM = Vale.Test.X64.Vale_memcpy [@__reduce__] let vm_dom = [t64_mod; t64_imm] open Vale.X64.MemoryAdapters (* Need to rearrange the order of arguments *) [@__reduce__] let vm_pre : VSig.vale_pre vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) -> VM.va_req_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) [@__reduce__] let vm_post : VSig.vale_post vm_dom = fun (c:V.va_code) (dst:b64) (src:ib64) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> VM.va_ens_Memcpy c va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) va_s1 f module VS = Vale.X64.State #reset-options "--print_effect_args --z3rlimit 200" (* The vale lemma doesn't quite suffice to prove the modifies clause expected of the interop layer *) [@__reduce__] let vm_lemma' (code:V.va_code) (_win:bool) (dst:b64) (src:ib64) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires vm_pre code dst src va_s0) (ensures (fun (va_s1, f) -> V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\ vm_post code dst src va_s0 va_s1 f /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_immbuffer src) /\ ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer dst) /\ ME.buffer_writeable (as_vale_buffer dst) /\ ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer dst)) ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1) )) = let va_s1, f = VM.va_lemma_Memcpy code va_s0 IA.win (as_vale_buffer dst) (as_vale_immbuffer src) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt64 dst; (va_s1, f) (* Prove that vm_lemma' has the required type *) let vm_lemma = as_t #(VSig.vale_sig_stdcall vm_pre vm_post) vm_lemma' let code_Memcpy = VM.va_code_Memcpy IA.win (* Here's the type expected for the memcpy wrapper *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Test.X64.Vale_memcpy.fsti.checked", "Vale.Test.X64.Args.fsti.checked", "Vale.Lib.X64.Cpuidstdcall.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "Vale.AsLowStar.Test.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.Test.X64.Vale_memcpy", "short_module": "VM" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall", "Vale.AsLowStar.Test.code_Memcpy", "Vale.AsLowStar.Test.vm_dom", "Prims.Nil", "Vale.Interop.Base.arg", "Vale.AsLowStar.Wrapper.pre_rel_generic", "Vale.Interop.X64.max_stdcall", "Vale.Interop.X64.arg_reg_stdcall", "Vale.AsLowStar.Test.vm_pre", "Vale.AsLowStar.Wrapper.post_rel_generic", "Vale.AsLowStar.Test.vm_post", "Vale.AsLowStar.Wrapper.mk_prediction", "Vale.Interop.X64.regs_modified_stdcall", "Vale.Interop.X64.xmms_modified_stdcall", "Vale.AsLowStar.Test.vm_lemma", "Vale.Interop.Assumptions.win" ]
[]
false
false
false
true
true
let lowstar_Memcpy_t =
IX64.as_lowstar_sig_t_weak_stdcall code_Memcpy vm_dom [] _ _ (W.mk_prediction code_Memcpy vm_dom [] (vm_lemma code_Memcpy IA.win))
false
Steel.Effect.M.fst
Steel.Effect.M.lift_ens_x
val lift_ens_x (#a: Type u#a) (#pre: (a -> slprop)) (#b: Type u#b) (#post: _) (ens: (x: a -> ens_t u#b (pre x) b post)) (x: U.raise_t u#a u#b a) : ens_t u#(max a b) ((lift_post pre) x) (U.raise_t b) (lift_post post)
val lift_ens_x (#a: Type u#a) (#pre: (a -> slprop)) (#b: Type u#b) (#post: _) (ens: (x: a -> ens_t u#b (pre x) b post)) (x: U.raise_t u#a u#b a) : ens_t u#(max a b) ((lift_post pre) x) (U.raise_t b) (lift_post post)
let lift_ens_x (#a:Type u#a) (#pre:a -> slprop) (#b:Type u#b) (#post:_) (ens:(x:a -> ens_t u#b (pre x) b post)) : x:U.raise_t u#a u#b a -> ens_t u#(max a b) ((lift_post pre) x) (U.raise_t b) (lift_post post) = fun x -> (fun m0 y m1 -> (ens (U.downgrade_val x)) m0 (U.downgrade_val y) m1)
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 79, "end_line": 201, "start_col": 0, "start_line": 196 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame (* * However, the effect defined this way is not immediately usable from F* * * To see the issue, consider again the `bind` combinator we defined above with * explicit universe annotations: *) let bind_explicit_univs (a:Type u#a) (b:Type u#a) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g (* * In the combinator, both the computation return types are in the same universe, * and the combinator itself is polymorphic in that single universe * * However, composing computations whose result types are in different universes * is useful. For example, composition of a computation returning an existential * (p:Type0 & x:int{p}) that lives in u#1 with a continuation that projects and returns * the int that lives in u#0. * * Hence, as with other F* effects, we would like to support a bind that is doubly * polymorphic in the result type of both the computations, e.g. something like * * let bind_double_univs (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) b pre_f post_g * (Sem.bind_lpre req_f ens_f req_g) * (Sem.bind_lpost req_f ens_f ens_g) = ... * * But F*, like Lean and Agda, and unlike Coq, lacks cumulativity of universes. * So the result type (repr u#(max a b) b ...) is not well-formed, since b has * universe u#b and not u#(max a b) * * We could explicitly lift the universes to get the following type: * * let bind_double_univs_raise (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) (raise_t b) ... * * (In the file below, we sketch this in actual code.) * * But this results in other complications: * 1. The user programs now have to explicitly eliminate raise_t (by downgrading) * 2. F* effect system will reject this bind definition, since it is unaware of the * universe lifting * * To get around this, we chose a different, more restrictive representation for the * Steel effect in Steel.Effect.fst. That definition is suitably doubly universe * polymorphic, at the expense of hiding the structure of the computation trees * needed for a full fidelity interleaving semantics. * * Please see that file for further discussions on the limitations of that * representation. * * In the meantime, we are working on adding universe cumulativity to F* that will * allow bind_double_univs to be defined and then we can switch to the action trees * based representation for the effect. *) /// Sketch for supporting different universes in the two computations module U = FStar.Universe module T = FStar.Tactics /// Auxiliary functions for lifting post, ens, etc. let lift_post #a (post:post_t u#a a) : post_t u#(max a b) (U.raise_t a) = fun x -> post (U.downgrade_val x) let lift_ens #pre #a #post (ens:ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post) = fun m0 x m1 -> ens m0 (U.downgrade_val x) m1 let lift_req_x (#a:Type u#a) (#pre:a -> slprop) (req:(x:a -> req_t (pre x))) : x:U.raise_t u#a u#b a -> req_t ((lift_post pre) x) = fun x -> req (U.downgrade_val x)
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
ens: (x: a -> Steel.Effect.M.ens_t (pre x) b post) -> x: FStar.Universe.raise_t a -> Steel.Effect.M.ens_t (Steel.Effect.M.lift_post pre x) (FStar.Universe.raise_t b) (Steel.Effect.M.lift_post post)
Prims.Tot
[ "total" ]
[]
[ "Steel.Memory.slprop", "Steel.Effect.M.post_t", "Steel.Effect.M.ens_t", "FStar.Universe.raise_t", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Instantiate.state", "FStar.Universe.downgrade_val", "Prims.prop", "Steel.Effect.M.lift_post" ]
[]
false
false
false
false
false
let lift_ens_x (#a: Type u#a) (#pre: (a -> slprop)) (#b: Type u#b) (#post: _) (ens: (x: a -> ens_t u#b (pre x) b post)) (x: U.raise_t u#a u#b a) : ens_t u#(max a b) ((lift_post pre) x) (U.raise_t b) (lift_post post) =
fun x -> (fun m0 y m1 -> (ens (U.downgrade_val x)) m0 (U.downgrade_val y) m1)
false
Steel.Effect.M.fst
Steel.Effect.M.lift_ens
val lift_ens (#pre #a #post: _) (ens: ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post)
val lift_ens (#pre #a #post: _) (ens: ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post)
let lift_ens #pre #a #post (ens:ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post) = fun m0 x m1 -> ens m0 (U.downgrade_val x) m1
{ "file_name": "lib/steel/Steel.Effect.M.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 46, "end_line": 190, "start_col": 0, "start_line": 188 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.M //Note: This file is standalone and not used anywhere else in the Steel codebase module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory open Steel.Semantics.Instantiate module Ins = Steel.Semantics.Instantiate open Steel.Memory (* * This module defines a layered effect over the CSL semantics * from Steel.Semantics.Hoare.MST * * The effect is defined with action trees as the underlying representation * for computations in the effect * * The effect combinators export the same specs as proved in the semantics * * The state typeclass in the semantics is instantiated with * Steel.Semantics.Instantiate * * This module is for illustration, our examples rely on Steel.Effect.fst * See the discussion towards the end of this file *) type pre_t = slprop u#1 type post_t (a:Type) = a -> slprop u#1 type req_t (pre:pre_t) = Sem.l_pre #state pre type ens_t (pre:pre_t) (a:Type) (post:post_t a) = Sem.l_post #state #a pre post /// Sem.m is the type of action trees in the semantics type repr (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) = Sem.m state a pre post req ens /// Effect return let return (a:Type) (x:a) (p:a -> slprop) (post:ens_t (p x) a p) : repr a (p x) p (Sem.return_lpre #state #a #p x post) post = Sem.Ret p x post /// Effect bind let bind (a:Type) (b:Type) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g /// A combinator for parallel computations let par (aL:Type) (preL:pre_t) (postL:post_t aL) (reqL:req_t preL) (ensL:ens_t preL aL postL) (f:repr aL preL postL reqL ensL) (aR:Type) (preR:pre_t) (postR:post_t aR) (reqR:req_t preR) (ensR:ens_t preR aR postR) (g:repr aR preR postR reqR ensR) : repr (aL & aR) (preL `star` preR) (fun (xL, xR) -> postL xL `star` postR xR) (Sem.par_lpre reqL reqR) (Sem.par_lpost reqL ensL reqR ensR) = Sem.Par f g /// Framing combinator let frame (a:Type) (pre:pre_t) (post:post_t a) (req:req_t pre) (ens:ens_t pre a post) (f:repr a pre post req ens) (frame:slprop) (f_frame:Sem.fp_prop frame) : repr a (pre `star` frame) (fun x -> post x `star` frame) (Sem.frame_lpre req f_frame) (Sem.frame_lpost req ens f_frame) = Sem.Frame f frame f_frame (* * However, the effect defined this way is not immediately usable from F* * * To see the issue, consider again the `bind` combinator we defined above with * explicit universe annotations: *) let bind_explicit_univs (a:Type u#a) (b:Type u#a) (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (post_g:post_t b) (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) (f:repr a pre_f post_f req_f ens_f) (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) : repr u#a b pre_f post_g (Sem.bind_lpre req_f ens_f req_g) (Sem.bind_lpost req_f ens_f ens_g) = Sem.Bind f g (* * In the combinator, both the computation return types are in the same universe, * and the combinator itself is polymorphic in that single universe * * However, composing computations whose result types are in different universes * is useful. For example, composition of a computation returning an existential * (p:Type0 & x:int{p}) that lives in u#1 with a continuation that projects and returns * the int that lives in u#0. * * Hence, as with other F* effects, we would like to support a bind that is doubly * polymorphic in the result type of both the computations, e.g. something like * * let bind_double_univs (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) b pre_f post_g * (Sem.bind_lpre req_f ens_f req_g) * (Sem.bind_lpost req_f ens_f ens_g) = ... * * But F*, like Lean and Agda, and unlike Coq, lacks cumulativity of universes. * So the result type (repr u#(max a b) b ...) is not well-formed, since b has * universe u#b and not u#(max a b) * * We could explicitly lift the universes to get the following type: * * let bind_double_univs_raise (a:Type u#a) (b:Type u#b) * (pre_f:pre_t) (post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) * (post_g:post_t b) * (req_g:(x:a -> req_t (post_f x))) (ens_g:(x:a -> ens_t (post_f x) b post_g)) * (f:repr a pre_f post_f req_f ens_f) * (g:(x:a -> repr b (post_f x) post_g (req_g x) (ens_g x))) * : repr u#(max a b) (raise_t b) ... * * (In the file below, we sketch this in actual code.) * * But this results in other complications: * 1. The user programs now have to explicitly eliminate raise_t (by downgrading) * 2. F* effect system will reject this bind definition, since it is unaware of the * universe lifting * * To get around this, we chose a different, more restrictive representation for the * Steel effect in Steel.Effect.fst. That definition is suitably doubly universe * polymorphic, at the expense of hiding the structure of the computation trees * needed for a full fidelity interleaving semantics. * * Please see that file for further discussions on the limitations of that * representation. * * In the meantime, we are working on adding universe cumulativity to F* that will * allow bind_double_univs to be defined and then we can switch to the action trees * based representation for the effect. *) /// Sketch for supporting different universes in the two computations module U = FStar.Universe module T = FStar.Tactics /// Auxiliary functions for lifting post, ens, etc. let lift_post #a (post:post_t u#a a) : post_t u#(max a b) (U.raise_t a) = fun x -> post (U.downgrade_val x)
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Instantiate.fsti.checked", "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Steel.Effect.M.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "Steel.Semantics.Instantiate", "short_module": "Ins" }, { "abbrev": false, "full_module": "Steel.Semantics.Instantiate", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
ens: Steel.Effect.M.ens_t pre a post -> Steel.Effect.M.ens_t pre (FStar.Universe.raise_t a) (Steel.Effect.M.lift_post post)
Prims.Tot
[ "total" ]
[]
[ "Steel.Effect.M.pre_t", "Steel.Effect.M.post_t", "Steel.Effect.M.ens_t", "Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem", "Steel.Semantics.Instantiate.state", "FStar.Universe.raise_t", "FStar.Universe.downgrade_val", "Prims.prop", "Steel.Effect.M.lift_post" ]
[]
false
false
false
false
false
let lift_ens #pre #a #post (ens: ens_t u#a pre a post) : ens_t u#(max a b) pre (U.raise_t a) (lift_post post) =
fun m0 x m1 -> ens m0 (U.downgrade_val x) m1
false