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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ID2.fst | ID2.sat | val sat (w: pure_wp 'a) : Type0 | val sat (w: pure_wp 'a) : Type0 | let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True) | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 4,
"start_col": 0,
"start_line": 4
} | module ID2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | w: Prims.pure_wp 'a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"Prims.l_True"
] | [] | false | false | false | true | true | let sat (w: pure_wp 'a) : Type0 =
| w (fun _ -> True) | false |
ID2.fst | ID2.repr | val repr (a: Type u#aa) (wp: pure_wp a) : Type u#aa | val repr (a: Type u#aa) (wp: pure_wp a) : Type u#aa | let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v} | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 9,
"start_col": 0,
"start_line": 8
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> wp: Prims.pure_wp a -> Type | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"Prims.squash",
"ID2.sat",
"Prims.l_Forall",
"Prims.l_imp"
] | [] | false | false | false | true | true | let repr (a: Type u#aa) (wp: pure_wp a) : Type u#aa =
| squash (sat wp) -> v: a{forall p. wp p ==> p v} | false |
LowParse.Spec.Tac.Combinators.fst | LowParse.Spec.Tac.Combinators.destruct_lhs_pairs | val destruct_lhs_pairs (t: FStar.Tactics.term) (n: nat) : FStar.Tactics.Tac unit | val destruct_lhs_pairs (t: FStar.Tactics.term) (n: nat) : FStar.Tactics.Tac unit | let rec destruct_lhs_pairs (t: FStar.Tactics.term) (n: nat) : FStar.Tactics.Tac unit =
if n = 0
then trefl ()
else begin
destruct t;
let a = intro () in
let b = intro () in
let abeq = intro () in
rewrite abeq;
destruct_lhs_pairs (binder_to_term a) (n - 1)
end | {
"file_name": "src/lowparse/LowParse.Spec.Tac.Combinators.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 18,
"start_col": 0,
"start_line": 8
} | module LowParse.Spec.Tac.Combinators
include LowParse.Spec.Combinators
open LowParse.TacLib
(* for structs *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.TacLib.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Tac.Combinators.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.TacLib",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Tac",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Tac",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term -> n: Prims.nat -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"FStar.Tactics.V1.Derived.trefl",
"Prims.unit",
"Prims.bool",
"LowParse.Spec.Tac.Combinators.destruct_lhs_pairs",
"Prims.op_Subtraction",
"FStar.Tactics.V1.Derived.binder_to_term",
"FStar.Stubs.Tactics.V1.Builtins.rewrite",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Tactics.V1.Builtins.intro",
"FStar.Tactics.V1.Derived.destruct"
] | [
"recursion"
] | false | true | false | false | false | let rec destruct_lhs_pairs (t: FStar.Tactics.term) (n: nat) : FStar.Tactics.Tac unit =
| if n = 0
then trefl ()
else
(destruct t;
let a = intro () in
let b = intro () in
let abeq = intro () in
rewrite abeq;
destruct_lhs_pairs (binder_to_term a) (n - 1)) | false |
ID2.fst | ID2.l | val l: Prims.unit -> int | val l: Prims.unit -> int | let l () : int = reify (test_f ()) () | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 76,
"start_col": 0,
"start_line": 76
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) ()
let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f
unfold
let if_then_else_wp (#a:Type) (wp1 wp2:pure_wp a) (p:bool) : pure_wp a =
elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post))
let if_then_else (a : Type)
(wp1 wp2 : pure_wp a)
(f : repr a wp1)
(g : repr a wp2) (p : bool)
: Type
= repr a (if_then_else_wp wp1 wp2 p)
// requires to prove that
// p ==> f <: (if_then_else p f g)
// ~p ==> g <: (if_then_else p f g)
// if the effect definition fails, add lemmas for the
// above with smtpats
total
reifiable
reflectable
effect {
ID (a:Type) (wp:pure_wp a)
with { repr; return; bind; subcomp; if_then_else }
}
let lift_pure_nd (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a wp
= elim_pure_wp_monotonicity wp;
fun _ -> f ()
sub_effect PURE ~> ID = lift_pure_nd
// this requires using a good if_then_else, but why?
let rec count (n:nat) : ID int (as_pure_wp (fun p -> forall r. p r)) =
if n = 0 then 0 else count (n-1)
(* Checking that it's kind of usable *)
val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3))
let test_f () = 5
let test_2 () : ID int (as_pure_wp (fun p -> p 5)) = 5 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"ID2.test_f",
"Prims.int"
] | [] | false | false | false | true | false | let l () : int =
| reify (test_f ()) () | false |
LowParse.Spec.Sum.fst | LowParse.Spec.Sum.serialize_dsum | val serialize_dsum
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
: Pure (serializer (parse_dsum s pt f g))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True)) | val serialize_dsum
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
: Pure (serializer (parse_dsum s pt f g))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True)) | let serialize_dsum
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
: Pure (serializer (parse_dsum s pt f g))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg) | {
"file_name": "src/lowparse/LowParse.Spec.Sum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 86,
"end_line": 921,
"start_col": 0,
"start_line": 908
} | module LowParse.Spec.Sum
include LowParse.Spec.Enum
module Seq = FStar.Seq
let synth_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: data)
: GTot (type_of_tag (tag_of_data x))
= synth_case_recip (tag_of_data x) x
noeq
type sum =
| Sum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (enum_key e))) ->
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
sum
inline_for_extraction
let sum_key_type (t: sum) : Tot eqtype =
match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let sum_repr_type (t: sum) : Tot eqtype =
match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
inline_for_extraction
let sum_key (t: sum) : Tot Type =
enum_key (sum_enum t)
inline_for_extraction
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t)
(requires True)
(ensures (fun k' -> k' == (k <: sum_key_type t)))
= k
inline_for_extraction
let sum_type (t: sum) : Tot Type =
match t with
| Sum _ _ _ data _ _ _ _ _ _ -> data
inline_for_extraction
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) =
match t with
| Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
inline_for_extraction
let sum_cases (t: sum) (x: sum_key t) : Type =
refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x
inline_for_extraction
let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type =
match t with
| Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag
let weaken_parse_cases_kind
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
: Tot parser_kind
= let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in
glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else default_parser_kind
) (List.Tot.map fst (sum_enum s))
inline_for_extraction
let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) =
match s with
| Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
(synth_injective (synth_sum_case s k))
= Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
let parse_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
= synth_sum_case_injective s x;
weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
let parse_sum_cases_eq
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with
| None -> None
| Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
))
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
let parse_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (dfst (f x)) (sum_cases s x))
=
synth_sum_case_injective s x;
dsnd (f x) `parse_synth` synth_sum_case s x
let parse_sum_cases_eq'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input;
parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
let parse_sum'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(#k: parser_kind)
(pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
: Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
= parse_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_sum_kind
(kt: parser_kind)
(t: sum)
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
let parse_sum
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot (parser (parse_sum_kind kt t pc) (sum_type t))
= parse_sum' t p (parse_sum_cases t pc)
let parse_sum_eq'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match
// parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k
parse (parse_sum_cases' t pc k) input_k
with
| None -> None
| Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
(parse_sum_cases t pc)
(parse_enum_key p (sum_enum t))
(fun input -> ())
(fun k -> dfst (pc k))
(parse_sum_cases' t pc)
(fun k input -> parse_sum_cases_eq' t pc k input)
input
let parse_sum_eq
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_sum_eq' t p pc input;
match parse (parse_enum_key p (sum_enum t)) input with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_sum_case_injective t k;
parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
let parse_sum_eq''
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
let k = maybe_enum_key_of_repr (sum_enum t) k' in
begin match k with
| Known k ->
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
| _ -> None
end
))
= parse_sum_eq t p pc input;
parse_enum_key_eq p (sum_enum t) input
inline_for_extraction
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) ->
synth_case_recip k x
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
(synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
= Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
let serialize_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases' s f x))
= synth_sum_case_injective s x;
synth_sum_case_inverse s x;
(serialize_synth
_
(synth_sum_case s x)
(sr x)
(synth_sum_case_recip s x)
()
)
let serialize_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases s f x))
= Classical.forall_intro (parse_sum_cases_eq' s f x);
serialize_ext
(parse_sum_cases' s f x)
(serialize_sum_cases' s f sr x)
(parse_sum_cases s f x)
let serialize_sum'
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
(sc: ((x: sum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_sum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
#(parse_enum_key p (sum_enum t))
(serialize_enum_key p s (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
#pc
sc
let serialize_sum
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
: Pure (serializer (parse_sum t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion)
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
let serialize_sum_eq
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
(x: sum_type t)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_sum t s sc) x == (
let tg = sum_tag_of_data t x in
serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append`
serialize (sc tg) (synth_sum_case_recip t tg x)
)))
= let tg = sum_tag_of_data t x in
synth_sum_case_injective t tg;
synth_sum_case_inverse t tg;
serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
inline_for_extraction
let make_sum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
: Tot (
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
Tot sum)
= Sum key repr e data tag_of_data
let synth_case_recip_synth_case_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))}
synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y
)
inline_for_extraction
let make_sum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(synth_case_recip_synth_case: (
(x: key) ->
Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x))
))
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
))
: Tot sum
= make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y ->
let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) =
synth_case_recip_synth_case x in
assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y))
(fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
(* Sum with default case *)
inline_for_extraction
let dsum_type_of_tag'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(k: maybe_enum_key e)
: Type
= match k with
| Unknown _ -> type_of_unknown_tag
| Known k -> type_of_known_tag k
let synth_dsum_case'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x))))
(synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x))))
(xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
: GTot data
= let (| x, y |) = xy in
match x with
| Unknown x -> synth_unknown_case x y
| Known x -> synth_known_case x y
let synth_dsum_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(y: data)
: GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
= let tg = tag_of_data y in
(| tg, synth_case_recip tg y |)
noeq
type dsum =
| DSum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (maybe_enum_key e))) ->
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
inline_for_extraction
let dsum_key_type (t: dsum) : Tot eqtype =
match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let dsum_repr_type (t: dsum) : Tot eqtype =
match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
inline_for_extraction
let dsum_key (t: dsum) : Tot Type =
maybe_enum_key (dsum_enum t)
inline_for_extraction
let dsum_known_key (t: dsum) : Tot Type =
enum_key (dsum_enum t)
inline_for_extraction
let dsum_unknown_key (t: dsum) : Tot Type =
unknown_enum_repr (dsum_enum t)
inline_for_extraction
let dsum_type (t: dsum) : Tot Type =
//NS: this was rewritten from `let DSum ... data .. = t in data`
//to workaround a glitch in desugaring the above, which introduces
//an additional, unreduced let binding for extraction
match t with
| DSum _ _ _ data _ _ _ _ _ _ _ -> data
inline_for_extraction
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) =
match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
inline_for_extraction
let dsum_cases (t: dsum) (x: dsum_key t) : Type =
refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x
inline_for_extraction
let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) =
match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) ->
type_of_known_tag
inline_for_extraction
let dsum_type_of_unknown_tag (t: dsum) : Tot Type =
match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) ->
type_of_unknown_tag
inline_for_extraction
let dsum_type_of_tag (t: dsum) =
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let weaken_parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k' : parser_kind)
: Tot parser_kind
= let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in
glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else k'
) (List.Tot.map fst (dsum_enum s)) `glb` k'
let weaken_parse_dsum_cases_kind'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k' : parser_kind)
(p: parser k' (dsum_type_of_unknown_tag s))
: Tot parser_kind
= weaken_parse_dsum_cases_kind s f k'
inline_for_extraction
let synth_dsum_case
(s: dsum)
: Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
= match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
inline_for_extraction
let synth_dsum_case_recip
(s: dsum)
: Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
= match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
let synth_dsum_case_injective
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_injective (synth_dsum_case s x))
= let f
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(requires (synth_dsum_case s x y1 == synth_dsum_case s x y2))
(ensures (y1 == y2))
= let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) =
DSum?.synth_case_recip_synth_case s x y1
in
let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) =
DSum?.synth_case_recip_synth_case s x y2
in
// FIXME: WHY WHY WHY is this assert necessary?
assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2);
()
in
let g
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2)
= Classical.move_requires (f y1) y2
in
Classical.forall_intro_2 g
let parse_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x')))
| Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
let parse_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
= synth_dsum_case_injective s x;
parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
let parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot parser_kind
= match x with
| Known k -> dfst (f k)
| _ -> k
let parse_dsum_type_of_tag'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x'))
| Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
let parse_dsum_cases'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
= synth_dsum_case_injective s x;
match x with
| Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
| Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
let parse_dsum_cases_eq'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
(input: bytes)
: Lemma
(parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
= synth_dsum_case_injective s x;
match x with
| Known x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input;
parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input
| Unknown x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input;
parse_synth_eq g (synth_dsum_case s (Unknown x')) input
let parse_dsum'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(#k: parser_kind)
(pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
: Tot (parser (and_then_kind kt k) (dsum_type t))
= parse_tagged_union
#kt
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_dsum_kind
(kt: parser_kind)
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k: parser_kind)
: Tot parser_kind
= and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
let parse_dsum
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag t))
: Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
= parse_dsum' t p (parse_dsum_cases t f g)
let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
let parse_dsum_eq_
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
let parse_dsum_eq'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq_ t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match k with
| Known k' ->
begin match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
| Unknown k' ->
begin match parse g input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
end
))
= parse_dsum_eq_ t p f g input;
let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in
match j with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_dsum_case_injective t k;
begin match k with
| Known k_ ->
parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k
| Unknown k_ ->
parse_synth_eq g (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k
end
let parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let synth_dsum_case_inverse
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x))
= let f
(y: refine_with_tag (dsum_tag_of_data s) (x))
: Lemma
(synth_dsum_case s x (synth_dsum_case_recip s x y) == y)
= DSum?.synth_case_synth_case_recip s y
in
Classical.forall_intro f
let serialize_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_type_of_tag s f g x))
= match x with
| Known x' ->
serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x)
| Unknown x' ->
serialize_ext g sg (parse_dsum_type_of_tag s f g x)
let serialize_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_cases s f g x))
= synth_dsum_case_injective s x;
synth_dsum_case_inverse s x;
serialize_synth
_
(synth_dsum_case s x)
(serialize_dsum_type_of_tag s f sr g sg x)
(synth_dsum_case_recip s x)
()
let serialize_dsum'
(#kt: parser_kind)
(t: dsum)
(#p: parser kt (dsum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
(sc: ((x: dsum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_dsum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(kt)
#(dsum_key t)
#(parse_maybe_enum_key p (dsum_enum t))
(serialize_maybe_enum_key p s (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
#pc
sc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Sum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.Sum.dsum ->
st: LowParse.Spec.Base.serializer pt ->
f:
(x: LowParse.Spec.Sum.dsum_known_key s
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag s x))) ->
sr:
(x: LowParse.Spec.Sum.dsum_known_key s
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) ->
sg: LowParse.Spec.Base.serializer g
-> Prims.Pure (LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_dsum s pt f g)) | Prims.Pure | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Sum.dsum",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Sum.dsum_repr_type",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.Sum.dsum_known_key",
"Prims.dtuple2",
"LowParse.Spec.Sum.dsum_type_of_known_tag",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Sum.dsum_type_of_unknown_tag",
"LowParse.Spec.Sum.serialize_dsum'",
"LowParse.Spec.Sum.weaken_parse_dsum_cases_kind",
"LowParse.Spec.Sum.parse_dsum_cases",
"LowParse.Spec.Sum.serialize_dsum_cases",
"LowParse.Spec.Sum.parse_dsum_kind",
"LowParse.Spec.Sum.dsum_type",
"LowParse.Spec.Sum.parse_dsum",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.l_True"
] | [] | false | false | false | false | false | let serialize_dsum
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
: Pure (serializer (parse_dsum s pt f g))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True)) =
| serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg) | false |
CSL.Semantics.fst | CSL.Semantics.step_req | val step_req:
#st: st ->
#a: Type u#a ->
#pre: st.hprop ->
#post: post_t st a ->
f: m st a pre post ->
st.mem
-> Type0 | val step_req:
#st: st ->
#a: Type u#a ->
#pre: st.hprop ->
#post: post_t st a ->
f: m st a pre post ->
st.mem
-> Type0 | let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0 | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 261,
"start_col": 0,
"start_line": 259
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes 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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f: CSL.Semantics.m st a pre post -> _: Mkst0?.mem st -> Type0 | Prims.Tot | [
"total"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.post_t",
"CSL.Semantics.m",
"CSL.Semantics.__proj__Mkst0__item__mem",
"CSL.Semantics.__proj__Mkst0__item__interp",
"CSL.Semantics.__proj__Mkst0__item__star",
"CSL.Semantics.__proj__Mkst0__item__invariant"
] | [] | false | false | false | false | true | let step_req (#st: st) (#a: Type u#a) (#pre: st.hprop) (#post: post_t st a) (f: m st a pre post)
: st.mem -> Type0 =
| fun m0 -> st.interp (pre `st.star` (st.invariant m0)) m0 | false |
LowParse.Spec.Sum.fst | LowParse.Spec.Sum.synth_dsum_case_recip_synth_case_known_post | val synth_dsum_case_recip_synth_case_known_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case:
(x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x
-> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip:
(k: maybe_enum_key e -> (refine_with_tag tag_of_data k)
-> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(x: key)
: GTot Type0 | val synth_dsum_case_recip_synth_case_known_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case:
(x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x
-> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip:
(k: maybe_enum_key e -> (refine_with_tag tag_of_data k)
-> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(x: key)
: GTot Type0 | let synth_dsum_case_recip_synth_case_known_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_known_tag x) . {:pattern (synth_case_recip (Known x) (synth_case (Known x) y))}
synth_case_recip (Known x) (synth_case (Known x) y) == y
) | {
"file_name": "src/lowparse/LowParse.Spec.Sum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 938,
"start_col": 0,
"start_line": 923
} | module LowParse.Spec.Sum
include LowParse.Spec.Enum
module Seq = FStar.Seq
let synth_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: data)
: GTot (type_of_tag (tag_of_data x))
= synth_case_recip (tag_of_data x) x
noeq
type sum =
| Sum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (enum_key e))) ->
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
sum
inline_for_extraction
let sum_key_type (t: sum) : Tot eqtype =
match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let sum_repr_type (t: sum) : Tot eqtype =
match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
inline_for_extraction
let sum_key (t: sum) : Tot Type =
enum_key (sum_enum t)
inline_for_extraction
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t)
(requires True)
(ensures (fun k' -> k' == (k <: sum_key_type t)))
= k
inline_for_extraction
let sum_type (t: sum) : Tot Type =
match t with
| Sum _ _ _ data _ _ _ _ _ _ -> data
inline_for_extraction
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) =
match t with
| Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
inline_for_extraction
let sum_cases (t: sum) (x: sum_key t) : Type =
refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x
inline_for_extraction
let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type =
match t with
| Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag
let weaken_parse_cases_kind
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
: Tot parser_kind
= let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in
glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else default_parser_kind
) (List.Tot.map fst (sum_enum s))
inline_for_extraction
let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) =
match s with
| Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
(synth_injective (synth_sum_case s k))
= Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
let parse_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
= synth_sum_case_injective s x;
weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
let parse_sum_cases_eq
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with
| None -> None
| Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
))
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
let parse_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (dfst (f x)) (sum_cases s x))
=
synth_sum_case_injective s x;
dsnd (f x) `parse_synth` synth_sum_case s x
let parse_sum_cases_eq'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input;
parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
let parse_sum'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(#k: parser_kind)
(pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
: Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
= parse_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_sum_kind
(kt: parser_kind)
(t: sum)
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
let parse_sum
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot (parser (parse_sum_kind kt t pc) (sum_type t))
= parse_sum' t p (parse_sum_cases t pc)
let parse_sum_eq'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match
// parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k
parse (parse_sum_cases' t pc k) input_k
with
| None -> None
| Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
(parse_sum_cases t pc)
(parse_enum_key p (sum_enum t))
(fun input -> ())
(fun k -> dfst (pc k))
(parse_sum_cases' t pc)
(fun k input -> parse_sum_cases_eq' t pc k input)
input
let parse_sum_eq
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_sum_eq' t p pc input;
match parse (parse_enum_key p (sum_enum t)) input with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_sum_case_injective t k;
parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
let parse_sum_eq''
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
let k = maybe_enum_key_of_repr (sum_enum t) k' in
begin match k with
| Known k ->
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
| _ -> None
end
))
= parse_sum_eq t p pc input;
parse_enum_key_eq p (sum_enum t) input
inline_for_extraction
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) ->
synth_case_recip k x
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
(synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
= Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
let serialize_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases' s f x))
= synth_sum_case_injective s x;
synth_sum_case_inverse s x;
(serialize_synth
_
(synth_sum_case s x)
(sr x)
(synth_sum_case_recip s x)
()
)
let serialize_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases s f x))
= Classical.forall_intro (parse_sum_cases_eq' s f x);
serialize_ext
(parse_sum_cases' s f x)
(serialize_sum_cases' s f sr x)
(parse_sum_cases s f x)
let serialize_sum'
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
(sc: ((x: sum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_sum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
#(parse_enum_key p (sum_enum t))
(serialize_enum_key p s (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
#pc
sc
let serialize_sum
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
: Pure (serializer (parse_sum t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion)
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
let serialize_sum_eq
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
(x: sum_type t)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_sum t s sc) x == (
let tg = sum_tag_of_data t x in
serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append`
serialize (sc tg) (synth_sum_case_recip t tg x)
)))
= let tg = sum_tag_of_data t x in
synth_sum_case_injective t tg;
synth_sum_case_inverse t tg;
serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
inline_for_extraction
let make_sum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
: Tot (
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
Tot sum)
= Sum key repr e data tag_of_data
let synth_case_recip_synth_case_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))}
synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y
)
inline_for_extraction
let make_sum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(synth_case_recip_synth_case: (
(x: key) ->
Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x))
))
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
))
: Tot sum
= make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y ->
let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) =
synth_case_recip_synth_case x in
assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y))
(fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
(* Sum with default case *)
inline_for_extraction
let dsum_type_of_tag'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(k: maybe_enum_key e)
: Type
= match k with
| Unknown _ -> type_of_unknown_tag
| Known k -> type_of_known_tag k
let synth_dsum_case'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x))))
(synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x))))
(xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
: GTot data
= let (| x, y |) = xy in
match x with
| Unknown x -> synth_unknown_case x y
| Known x -> synth_known_case x y
let synth_dsum_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(y: data)
: GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
= let tg = tag_of_data y in
(| tg, synth_case_recip tg y |)
noeq
type dsum =
| DSum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (maybe_enum_key e))) ->
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
inline_for_extraction
let dsum_key_type (t: dsum) : Tot eqtype =
match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let dsum_repr_type (t: dsum) : Tot eqtype =
match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
inline_for_extraction
let dsum_key (t: dsum) : Tot Type =
maybe_enum_key (dsum_enum t)
inline_for_extraction
let dsum_known_key (t: dsum) : Tot Type =
enum_key (dsum_enum t)
inline_for_extraction
let dsum_unknown_key (t: dsum) : Tot Type =
unknown_enum_repr (dsum_enum t)
inline_for_extraction
let dsum_type (t: dsum) : Tot Type =
//NS: this was rewritten from `let DSum ... data .. = t in data`
//to workaround a glitch in desugaring the above, which introduces
//an additional, unreduced let binding for extraction
match t with
| DSum _ _ _ data _ _ _ _ _ _ _ -> data
inline_for_extraction
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) =
match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
inline_for_extraction
let dsum_cases (t: dsum) (x: dsum_key t) : Type =
refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x
inline_for_extraction
let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) =
match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) ->
type_of_known_tag
inline_for_extraction
let dsum_type_of_unknown_tag (t: dsum) : Tot Type =
match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) ->
type_of_unknown_tag
inline_for_extraction
let dsum_type_of_tag (t: dsum) =
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let weaken_parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k' : parser_kind)
: Tot parser_kind
= let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in
glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else k'
) (List.Tot.map fst (dsum_enum s)) `glb` k'
let weaken_parse_dsum_cases_kind'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k' : parser_kind)
(p: parser k' (dsum_type_of_unknown_tag s))
: Tot parser_kind
= weaken_parse_dsum_cases_kind s f k'
inline_for_extraction
let synth_dsum_case
(s: dsum)
: Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
= match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
inline_for_extraction
let synth_dsum_case_recip
(s: dsum)
: Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
= match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
let synth_dsum_case_injective
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_injective (synth_dsum_case s x))
= let f
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(requires (synth_dsum_case s x y1 == synth_dsum_case s x y2))
(ensures (y1 == y2))
= let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) =
DSum?.synth_case_recip_synth_case s x y1
in
let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) =
DSum?.synth_case_recip_synth_case s x y2
in
// FIXME: WHY WHY WHY is this assert necessary?
assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2);
()
in
let g
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2)
= Classical.move_requires (f y1) y2
in
Classical.forall_intro_2 g
let parse_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x')))
| Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
let parse_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
= synth_dsum_case_injective s x;
parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
let parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot parser_kind
= match x with
| Known k -> dfst (f k)
| _ -> k
let parse_dsum_type_of_tag'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x'))
| Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
let parse_dsum_cases'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
= synth_dsum_case_injective s x;
match x with
| Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
| Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
let parse_dsum_cases_eq'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
(input: bytes)
: Lemma
(parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
= synth_dsum_case_injective s x;
match x with
| Known x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input;
parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input
| Unknown x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input;
parse_synth_eq g (synth_dsum_case s (Unknown x')) input
let parse_dsum'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(#k: parser_kind)
(pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
: Tot (parser (and_then_kind kt k) (dsum_type t))
= parse_tagged_union
#kt
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_dsum_kind
(kt: parser_kind)
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k: parser_kind)
: Tot parser_kind
= and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
let parse_dsum
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag t))
: Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
= parse_dsum' t p (parse_dsum_cases t f g)
let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
let parse_dsum_eq_
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
let parse_dsum_eq'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq_ t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match k with
| Known k' ->
begin match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
| Unknown k' ->
begin match parse g input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
end
))
= parse_dsum_eq_ t p f g input;
let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in
match j with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_dsum_case_injective t k;
begin match k with
| Known k_ ->
parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k
| Unknown k_ ->
parse_synth_eq g (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k
end
let parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let synth_dsum_case_inverse
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x))
= let f
(y: refine_with_tag (dsum_tag_of_data s) (x))
: Lemma
(synth_dsum_case s x (synth_dsum_case_recip s x y) == y)
= DSum?.synth_case_synth_case_recip s y
in
Classical.forall_intro f
let serialize_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_type_of_tag s f g x))
= match x with
| Known x' ->
serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x)
| Unknown x' ->
serialize_ext g sg (parse_dsum_type_of_tag s f g x)
let serialize_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_cases s f g x))
= synth_dsum_case_injective s x;
synth_dsum_case_inverse s x;
serialize_synth
_
(synth_dsum_case s x)
(serialize_dsum_type_of_tag s f sr g sg x)
(synth_dsum_case_recip s x)
()
let serialize_dsum'
(#kt: parser_kind)
(t: dsum)
(#p: parser kt (dsum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
(sc: ((x: dsum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_dsum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(kt)
#(dsum_key t)
#(parse_maybe_enum_key p (dsum_enum t))
(serialize_maybe_enum_key p s (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
#pc
sc
let serialize_dsum
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
: Pure (serializer (parse_dsum s pt f g))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Sum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
e: LowParse.Spec.Enum.enum key repr ->
tag_of_data: (_: data -> LowParse.Spec.Enum.maybe_enum_key e) ->
type_of_known_tag: (_: LowParse.Spec.Enum.enum_key e -> Type) ->
type_of_unknown_tag: Type ->
synth_case:
(
x: LowParse.Spec.Enum.maybe_enum_key e ->
y: LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x
-> LowParse.Spec.Base.refine_with_tag tag_of_data x) ->
synth_case_recip:
(k: LowParse.Spec.Enum.maybe_enum_key e -> _: LowParse.Spec.Base.refine_with_tag tag_of_data k
-> LowParse.Spec.Sum.dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k) ->
x: key
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.eqtype",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Sum.dsum_type_of_tag'",
"LowParse.Spec.Base.refine_with_tag",
"Prims.l_imp",
"Prims.b2t",
"LowParse.Spec.Enum.list_mem",
"LowParse.Spec.Enum.list_map",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"Prims.l_Forall",
"Prims.eq2",
"LowParse.Spec.Enum.Known"
] | [] | false | false | false | false | true | let synth_dsum_case_recip_synth_case_known_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case:
(x: maybe_enum_key e -> y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x
-> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip:
(k: maybe_enum_key e -> (refine_with_tag tag_of_data k)
-> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(x: key)
: GTot Type0 =
| list_mem x (list_map fst e) ==>
(forall (y: type_of_known_tag x). {:pattern (synth_case_recip (Known x) (synth_case (Known x) y))}
synth_case_recip (Known x) (synth_case (Known x) y) == y) | false |
ID2.fst | ID2.subcomp | val subcomp (a: Type) (wp1 wp2: pure_wp a) (f: repr a wp1)
: Pure (repr a wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures fun _ -> True) | val subcomp (a: Type) (wp1 wp2: pure_wp a) (f: repr a wp1)
: Pure (repr a wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures fun _ -> True) | let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 31,
"start_col": 0,
"start_line": 25
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> wp1: Prims.pure_wp a -> wp2: Prims.pure_wp a -> f: ID2.repr a wp1
-> Prims.Pure (ID2.repr a wp2) | Prims.Pure | [] | [] | [
"Prims.pure_wp",
"ID2.repr",
"Prims.l_Forall",
"Prims.pure_post",
"Prims.l_imp",
"Prims.l_True"
] | [] | false | false | false | false | false | let subcomp (a: Type) (wp1 wp2: pure_wp a) (f: repr a wp1)
: Pure (repr a wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures fun _ -> True) =
| f | false |
ID2.fst | ID2.return | val return (a: Type) (x: a) : repr a (pure_return a x) | val return (a: Type) (x: a) : repr a (pure_return a x) | let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 12,
"start_col": 0,
"start_line": 11
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> ID2.repr a (FStar.Pervasives.pure_return a x) | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.Pervasives.pure_return",
"ID2.repr"
] | [] | false | false | false | false | false | let return (a: Type) (x: a) : repr a (pure_return a x) =
| fun () -> x | false |
ID2.fst | ID2.if_then_else_wp | val if_then_else_wp (#a: Type) (wp1 wp2: pure_wp a) (p: bool) : pure_wp a | val if_then_else_wp (#a: Type) (wp1 wp2: pure_wp a) (p: bool) : pure_wp a | let if_then_else_wp (#a:Type) (wp1 wp2:pure_wp a) (p:bool) : pure_wp a =
elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post)) | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 66,
"end_line": 36,
"start_col": 0,
"start_line": 34
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) ()
let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | wp1: Prims.pure_wp a -> wp2: Prims.pure_wp a -> p: Prims.bool -> Prims.pure_wp a | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"Prims.bool",
"FStar.Monotonic.Pure.as_pure_wp",
"Prims.pure_post",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.l_not",
"Prims.pure_pre",
"Prims.unit",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall"
] | [] | false | false | false | true | false | let if_then_else_wp (#a: Type) (wp1 wp2: pure_wp a) (p: bool) : pure_wp a =
| elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post)) | false |
ID2.fst | ID2.bind | val bind
(a b: Type)
(wp_v: pure_wp a)
(wp_f: (a -> pure_wp b))
(v: repr a wp_v)
(f: (x: a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f) | val bind
(a b: Type)
(wp_v: pure_wp a)
(wp_f: (a -> pure_wp b))
(v: repr a wp_v)
(f: (x: a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f) | let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) () | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 23,
"start_col": 0,
"start_line": 14
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
wp_v: Prims.pure_wp a ->
wp_f: (_: a -> Prims.pure_wp b) ->
v: ID2.repr a wp_v ->
f: (x: a -> ID2.repr b (wp_f x))
-> ID2.repr b (FStar.Pervasives.pure_bind_wp a b wp_v wp_f) | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"ID2.repr",
"Prims.squash",
"ID2.sat",
"FStar.Pervasives.pure_bind_wp",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.unit",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall"
] | [] | false | false | false | false | false | let bind
(a b: Type)
(wp_v: pure_wp a)
(wp_f: (a -> pure_wp b))
(v: repr a wp_v)
(f: (x: a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f) =
| elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) () | false |
LowParse.Spec.Sum.fst | LowParse.Spec.Sum.serialize_dsum_type_of_tag | val serialize_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_type_of_tag s f g x)) | val serialize_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_type_of_tag s f g x)) | let serialize_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_type_of_tag s f g x))
= match x with
| Known x' ->
serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x)
| Unknown x' ->
serialize_ext g sg (parse_dsum_type_of_tag s f g x) | {
"file_name": "src/lowparse/LowParse.Spec.Sum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 55,
"end_line": 866,
"start_col": 0,
"start_line": 853
} | module LowParse.Spec.Sum
include LowParse.Spec.Enum
module Seq = FStar.Seq
let synth_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: data)
: GTot (type_of_tag (tag_of_data x))
= synth_case_recip (tag_of_data x) x
noeq
type sum =
| Sum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (enum_key e))) ->
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
sum
inline_for_extraction
let sum_key_type (t: sum) : Tot eqtype =
match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let sum_repr_type (t: sum) : Tot eqtype =
match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
inline_for_extraction
let sum_key (t: sum) : Tot Type =
enum_key (sum_enum t)
inline_for_extraction
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t)
(requires True)
(ensures (fun k' -> k' == (k <: sum_key_type t)))
= k
inline_for_extraction
let sum_type (t: sum) : Tot Type =
match t with
| Sum _ _ _ data _ _ _ _ _ _ -> data
inline_for_extraction
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) =
match t with
| Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
inline_for_extraction
let sum_cases (t: sum) (x: sum_key t) : Type =
refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x
inline_for_extraction
let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type =
match t with
| Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag
let weaken_parse_cases_kind
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
: Tot parser_kind
= let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in
glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else default_parser_kind
) (List.Tot.map fst (sum_enum s))
inline_for_extraction
let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) =
match s with
| Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
(synth_injective (synth_sum_case s k))
= Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
let parse_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
= synth_sum_case_injective s x;
weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
let parse_sum_cases_eq
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with
| None -> None
| Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
))
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
let parse_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (dfst (f x)) (sum_cases s x))
=
synth_sum_case_injective s x;
dsnd (f x) `parse_synth` synth_sum_case s x
let parse_sum_cases_eq'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input;
parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
let parse_sum'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(#k: parser_kind)
(pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
: Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
= parse_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_sum_kind
(kt: parser_kind)
(t: sum)
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
let parse_sum
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot (parser (parse_sum_kind kt t pc) (sum_type t))
= parse_sum' t p (parse_sum_cases t pc)
let parse_sum_eq'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match
// parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k
parse (parse_sum_cases' t pc k) input_k
with
| None -> None
| Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
(parse_sum_cases t pc)
(parse_enum_key p (sum_enum t))
(fun input -> ())
(fun k -> dfst (pc k))
(parse_sum_cases' t pc)
(fun k input -> parse_sum_cases_eq' t pc k input)
input
let parse_sum_eq
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_sum_eq' t p pc input;
match parse (parse_enum_key p (sum_enum t)) input with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_sum_case_injective t k;
parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
let parse_sum_eq''
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
let k = maybe_enum_key_of_repr (sum_enum t) k' in
begin match k with
| Known k ->
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
| _ -> None
end
))
= parse_sum_eq t p pc input;
parse_enum_key_eq p (sum_enum t) input
inline_for_extraction
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) ->
synth_case_recip k x
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
(synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
= Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
let serialize_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases' s f x))
= synth_sum_case_injective s x;
synth_sum_case_inverse s x;
(serialize_synth
_
(synth_sum_case s x)
(sr x)
(synth_sum_case_recip s x)
()
)
let serialize_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases s f x))
= Classical.forall_intro (parse_sum_cases_eq' s f x);
serialize_ext
(parse_sum_cases' s f x)
(serialize_sum_cases' s f sr x)
(parse_sum_cases s f x)
let serialize_sum'
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
(sc: ((x: sum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_sum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
#(parse_enum_key p (sum_enum t))
(serialize_enum_key p s (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
#pc
sc
let serialize_sum
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
: Pure (serializer (parse_sum t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion)
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
let serialize_sum_eq
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
(x: sum_type t)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_sum t s sc) x == (
let tg = sum_tag_of_data t x in
serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append`
serialize (sc tg) (synth_sum_case_recip t tg x)
)))
= let tg = sum_tag_of_data t x in
synth_sum_case_injective t tg;
synth_sum_case_inverse t tg;
serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
inline_for_extraction
let make_sum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
: Tot (
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
Tot sum)
= Sum key repr e data tag_of_data
let synth_case_recip_synth_case_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))}
synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y
)
inline_for_extraction
let make_sum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(synth_case_recip_synth_case: (
(x: key) ->
Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x))
))
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
))
: Tot sum
= make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y ->
let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) =
synth_case_recip_synth_case x in
assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y))
(fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
(* Sum with default case *)
inline_for_extraction
let dsum_type_of_tag'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(k: maybe_enum_key e)
: Type
= match k with
| Unknown _ -> type_of_unknown_tag
| Known k -> type_of_known_tag k
let synth_dsum_case'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x))))
(synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x))))
(xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
: GTot data
= let (| x, y |) = xy in
match x with
| Unknown x -> synth_unknown_case x y
| Known x -> synth_known_case x y
let synth_dsum_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(y: data)
: GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
= let tg = tag_of_data y in
(| tg, synth_case_recip tg y |)
noeq
type dsum =
| DSum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (maybe_enum_key e))) ->
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
inline_for_extraction
let dsum_key_type (t: dsum) : Tot eqtype =
match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let dsum_repr_type (t: dsum) : Tot eqtype =
match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
inline_for_extraction
let dsum_key (t: dsum) : Tot Type =
maybe_enum_key (dsum_enum t)
inline_for_extraction
let dsum_known_key (t: dsum) : Tot Type =
enum_key (dsum_enum t)
inline_for_extraction
let dsum_unknown_key (t: dsum) : Tot Type =
unknown_enum_repr (dsum_enum t)
inline_for_extraction
let dsum_type (t: dsum) : Tot Type =
//NS: this was rewritten from `let DSum ... data .. = t in data`
//to workaround a glitch in desugaring the above, which introduces
//an additional, unreduced let binding for extraction
match t with
| DSum _ _ _ data _ _ _ _ _ _ _ -> data
inline_for_extraction
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) =
match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
inline_for_extraction
let dsum_cases (t: dsum) (x: dsum_key t) : Type =
refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x
inline_for_extraction
let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) =
match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) ->
type_of_known_tag
inline_for_extraction
let dsum_type_of_unknown_tag (t: dsum) : Tot Type =
match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) ->
type_of_unknown_tag
inline_for_extraction
let dsum_type_of_tag (t: dsum) =
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let weaken_parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k' : parser_kind)
: Tot parser_kind
= let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in
glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else k'
) (List.Tot.map fst (dsum_enum s)) `glb` k'
let weaken_parse_dsum_cases_kind'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k' : parser_kind)
(p: parser k' (dsum_type_of_unknown_tag s))
: Tot parser_kind
= weaken_parse_dsum_cases_kind s f k'
inline_for_extraction
let synth_dsum_case
(s: dsum)
: Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
= match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
inline_for_extraction
let synth_dsum_case_recip
(s: dsum)
: Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
= match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
let synth_dsum_case_injective
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_injective (synth_dsum_case s x))
= let f
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(requires (synth_dsum_case s x y1 == synth_dsum_case s x y2))
(ensures (y1 == y2))
= let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) =
DSum?.synth_case_recip_synth_case s x y1
in
let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) =
DSum?.synth_case_recip_synth_case s x y2
in
// FIXME: WHY WHY WHY is this assert necessary?
assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2);
()
in
let g
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2)
= Classical.move_requires (f y1) y2
in
Classical.forall_intro_2 g
let parse_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x')))
| Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
let parse_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
= synth_dsum_case_injective s x;
parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
let parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot parser_kind
= match x with
| Known k -> dfst (f k)
| _ -> k
let parse_dsum_type_of_tag'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x'))
| Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
let parse_dsum_cases'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
= synth_dsum_case_injective s x;
match x with
| Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
| Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
let parse_dsum_cases_eq'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
(input: bytes)
: Lemma
(parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
= synth_dsum_case_injective s x;
match x with
| Known x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input;
parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input
| Unknown x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input;
parse_synth_eq g (synth_dsum_case s (Unknown x')) input
let parse_dsum'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(#k: parser_kind)
(pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
: Tot (parser (and_then_kind kt k) (dsum_type t))
= parse_tagged_union
#kt
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_dsum_kind
(kt: parser_kind)
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k: parser_kind)
: Tot parser_kind
= and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
let parse_dsum
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag t))
: Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
= parse_dsum' t p (parse_dsum_cases t f g)
let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
let parse_dsum_eq_
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
let parse_dsum_eq'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq_ t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match k with
| Known k' ->
begin match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
| Unknown k' ->
begin match parse g input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
end
))
= parse_dsum_eq_ t p f g input;
let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in
match j with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_dsum_case_injective t k;
begin match k with
| Known k_ ->
parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k
| Unknown k_ ->
parse_synth_eq g (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k
end
let parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let synth_dsum_case_inverse
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x))
= let f
(y: refine_with_tag (dsum_tag_of_data s) (x))
: Lemma
(synth_dsum_case s x (synth_dsum_case_recip s x y) == y)
= DSum?.synth_case_synth_case_recip s y
in
Classical.forall_intro f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Sum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.Sum.dsum ->
f:
(x: LowParse.Spec.Sum.dsum_known_key s
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag s x))) ->
sr:
(x: LowParse.Spec.Sum.dsum_known_key s
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) ->
sg: LowParse.Spec.Base.serializer g ->
x: LowParse.Spec.Sum.dsum_key s
-> LowParse.Spec.Base.serializer (LowParse.Spec.Sum.parse_dsum_type_of_tag s f g x) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Sum.dsum",
"LowParse.Spec.Sum.dsum_known_key",
"Prims.dtuple2",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Sum.dsum_type_of_known_tag",
"LowParse.Spec.Base.serializer",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Sum.dsum_type_of_unknown_tag",
"LowParse.Spec.Sum.dsum_key",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Sum.dsum_key_type",
"LowParse.Spec.Sum.dsum_repr_type",
"LowParse.Spec.Sum.dsum_enum",
"LowParse.Spec.Base.serialize_ext",
"LowParse.Spec.Sum.weaken_parse_dsum_cases_kind",
"LowParse.Spec.Sum.dsum_type_of_tag",
"LowParse.Spec.Sum.parse_dsum_type_of_tag",
"LowParse.Spec.Enum.unknown_enum_repr"
] | [] | false | false | false | false | false | let serialize_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_type_of_tag s f g x)) =
| match x with
| Known x' -> serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x)
| Unknown x' -> serialize_ext g sg (parse_dsum_type_of_tag s f g x) | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_wp_monotonic | val tac_wp_monotonic : wp: FStar.Tactics.Effect.tac_wp_t0 a -> Prims.logical | let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 33,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | wp: FStar.Tactics.Effect.tac_wp_t0 a -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.tac_wp_t0",
"Prims.l_Forall",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"Prims.l_imp",
"Prims.logical"
] | [] | false | false | false | true | true | let tac_wp_monotonic (#a: Type) (wp: tac_wp_t0 a) =
| forall (ps: proofstate) (p: (__result a -> Type0)) (q: (__result a -> Type0)).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q) | false |
|
Spec.Agile.HMAC.fsti | Spec.Agile.HMAC.keysized | val keysized : a: Spec.Hash.Definitions.hash_alg -> l: Prims.nat -> Prims.logical | let keysized (a:hash_alg) (l:nat) =
l `less_than_max_input_length` a /\
l + block_length a < pow2 32 | {
"file_name": "specs/Spec.Agile.HMAC.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 12,
"start_col": 0,
"start_line": 10
} | module Spec.Agile.HMAC
open Spec.Hash.Definitions
open Lib.IntTypes
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let lbytes (l:nat) = b:bytes {Seq.length b = l} | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Agile.HMAC.fsti"
} | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> l: Prims.nat -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Spec.Hash.Definitions.less_than_max_input_length",
"Prims.op_LessThan",
"Prims.op_Addition",
"Spec.Hash.Definitions.block_length",
"Prims.pow2",
"Prims.logical"
] | [] | false | false | false | true | true | let keysized (a: hash_alg) (l: nat) =
| l `less_than_max_input_length` a /\ l + block_length a < pow2 32 | false |
|
ID2.fst | ID2.test_2 | val test_2: Prims.unit -> ID int (as_pure_wp (fun p -> p 5)) | val test_2: Prims.unit -> ID int (as_pure_wp (fun p -> p 5)) | let test_2 () : ID int (as_pure_wp (fun p -> p 5)) = 5 | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 74,
"start_col": 0,
"start_line": 74
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) ()
let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f
unfold
let if_then_else_wp (#a:Type) (wp1 wp2:pure_wp a) (p:bool) : pure_wp a =
elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post))
let if_then_else (a : Type)
(wp1 wp2 : pure_wp a)
(f : repr a wp1)
(g : repr a wp2) (p : bool)
: Type
= repr a (if_then_else_wp wp1 wp2 p)
// requires to prove that
// p ==> f <: (if_then_else p f g)
// ~p ==> g <: (if_then_else p f g)
// if the effect definition fails, add lemmas for the
// above with smtpats
total
reifiable
reflectable
effect {
ID (a:Type) (wp:pure_wp a)
with { repr; return; bind; subcomp; if_then_else }
}
let lift_pure_nd (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a wp
= elim_pure_wp_monotonicity wp;
fun _ -> f ()
sub_effect PURE ~> ID = lift_pure_nd
// this requires using a good if_then_else, but why?
let rec count (n:nat) : ID int (as_pure_wp (fun p -> forall r. p r)) =
if n = 0 then 0 else count (n-1)
(* Checking that it's kind of usable *)
val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3))
let test_f () = 5 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> ID2.ID Prims.int | ID2.ID | [] | [] | [
"Prims.unit",
"Prims.int",
"FStar.Monotonic.Pure.as_pure_wp",
"Prims.pure_post",
"Prims.pure_pre"
] | [] | false | true | false | false | false | let test_2 () : ID int (as_pure_wp (fun p -> p 5)) =
| 5 | false |
ID2.fst | ID2.count | val count (n: nat) : ID int (as_pure_wp (fun p -> forall r. p r)) | val count (n: nat) : ID int (as_pure_wp (fun p -> forall r. p r)) | let rec count (n:nat) : ID int (as_pure_wp (fun p -> forall r. p r)) =
if n = 0 then 0 else count (n-1) | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 67,
"start_col": 0,
"start_line": 66
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) ()
let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f
unfold
let if_then_else_wp (#a:Type) (wp1 wp2:pure_wp a) (p:bool) : pure_wp a =
elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post))
let if_then_else (a : Type)
(wp1 wp2 : pure_wp a)
(f : repr a wp1)
(g : repr a wp2) (p : bool)
: Type
= repr a (if_then_else_wp wp1 wp2 p)
// requires to prove that
// p ==> f <: (if_then_else p f g)
// ~p ==> g <: (if_then_else p f g)
// if the effect definition fails, add lemmas for the
// above with smtpats
total
reifiable
reflectable
effect {
ID (a:Type) (wp:pure_wp a)
with { repr; return; bind; subcomp; if_then_else }
}
let lift_pure_nd (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a wp
= elim_pure_wp_monotonicity wp;
fun _ -> f ()
sub_effect PURE ~> ID = lift_pure_nd | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> ID2.ID Prims.int | ID2.ID | [] | [] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"ID2.count",
"Prims.op_Subtraction",
"FStar.Monotonic.Pure.as_pure_wp",
"Prims.pure_post",
"Prims.l_Forall",
"Prims.l_True",
"Prims.pure_pre"
] | [
"recursion"
] | false | true | false | false | false | let rec count (n: nat) : ID int (as_pure_wp (fun p -> forall r. p r)) =
| if n = 0 then 0 else count (n - 1) | false |
ID2.fst | ID2.test_f | val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) | val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) | let test_f () = 5 | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 72,
"start_col": 0,
"start_line": 72
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) ()
let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f
unfold
let if_then_else_wp (#a:Type) (wp1 wp2:pure_wp a) (p:bool) : pure_wp a =
elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post))
let if_then_else (a : Type)
(wp1 wp2 : pure_wp a)
(f : repr a wp1)
(g : repr a wp2) (p : bool)
: Type
= repr a (if_then_else_wp wp1 wp2 p)
// requires to prove that
// p ==> f <: (if_then_else p f g)
// ~p ==> g <: (if_then_else p f g)
// if the effect definition fails, add lemmas for the
// above with smtpats
total
reifiable
reflectable
effect {
ID (a:Type) (wp:pure_wp a)
with { repr; return; bind; subcomp; if_then_else }
}
let lift_pure_nd (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a wp
= elim_pure_wp_monotonicity wp;
fun _ -> f ()
sub_effect PURE ~> ID = lift_pure_nd
// this requires using a good if_then_else, but why?
let rec count (n:nat) : ID int (as_pure_wp (fun p -> forall r. p r)) =
if n = 0 then 0 else count (n-1)
(* Checking that it's kind of usable *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> ID2.ID Prims.int | ID2.ID | [] | [] | [
"Prims.unit",
"Prims.int"
] | [] | false | true | false | false | false | let test_f () =
| 5 | false |
LowParse.Spec.Sum.fst | LowParse.Spec.Sum.parse_dsum_eq'' | val parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) | val parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) | let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input | {
"file_name": "src/lowparse/LowParse.Spec.Sum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 732,
"start_col": 0,
"start_line": 712
} | module LowParse.Spec.Sum
include LowParse.Spec.Enum
module Seq = FStar.Seq
let synth_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: data)
: GTot (type_of_tag (tag_of_data x))
= synth_case_recip (tag_of_data x) x
noeq
type sum =
| Sum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (enum_key e))) ->
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
sum
inline_for_extraction
let sum_key_type (t: sum) : Tot eqtype =
match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let sum_repr_type (t: sum) : Tot eqtype =
match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
inline_for_extraction
let sum_key (t: sum) : Tot Type =
enum_key (sum_enum t)
inline_for_extraction
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t)
(requires True)
(ensures (fun k' -> k' == (k <: sum_key_type t)))
= k
inline_for_extraction
let sum_type (t: sum) : Tot Type =
match t with
| Sum _ _ _ data _ _ _ _ _ _ -> data
inline_for_extraction
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) =
match t with
| Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
inline_for_extraction
let sum_cases (t: sum) (x: sum_key t) : Type =
refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x
inline_for_extraction
let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type =
match t with
| Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag
let weaken_parse_cases_kind
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
: Tot parser_kind
= let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in
glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else default_parser_kind
) (List.Tot.map fst (sum_enum s))
inline_for_extraction
let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) =
match s with
| Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
(synth_injective (synth_sum_case s k))
= Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
let parse_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
= synth_sum_case_injective s x;
weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
let parse_sum_cases_eq
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with
| None -> None
| Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
))
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
let parse_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (dfst (f x)) (sum_cases s x))
=
synth_sum_case_injective s x;
dsnd (f x) `parse_synth` synth_sum_case s x
let parse_sum_cases_eq'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input;
parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
let parse_sum'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(#k: parser_kind)
(pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
: Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
= parse_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_sum_kind
(kt: parser_kind)
(t: sum)
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
let parse_sum
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot (parser (parse_sum_kind kt t pc) (sum_type t))
= parse_sum' t p (parse_sum_cases t pc)
let parse_sum_eq'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match
// parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k
parse (parse_sum_cases' t pc k) input_k
with
| None -> None
| Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
(parse_sum_cases t pc)
(parse_enum_key p (sum_enum t))
(fun input -> ())
(fun k -> dfst (pc k))
(parse_sum_cases' t pc)
(fun k input -> parse_sum_cases_eq' t pc k input)
input
let parse_sum_eq
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_sum_eq' t p pc input;
match parse (parse_enum_key p (sum_enum t)) input with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_sum_case_injective t k;
parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
let parse_sum_eq''
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
let k = maybe_enum_key_of_repr (sum_enum t) k' in
begin match k with
| Known k ->
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
| _ -> None
end
))
= parse_sum_eq t p pc input;
parse_enum_key_eq p (sum_enum t) input
inline_for_extraction
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) ->
synth_case_recip k x
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
(synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
= Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
let serialize_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases' s f x))
= synth_sum_case_injective s x;
synth_sum_case_inverse s x;
(serialize_synth
_
(synth_sum_case s x)
(sr x)
(synth_sum_case_recip s x)
()
)
let serialize_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases s f x))
= Classical.forall_intro (parse_sum_cases_eq' s f x);
serialize_ext
(parse_sum_cases' s f x)
(serialize_sum_cases' s f sr x)
(parse_sum_cases s f x)
let serialize_sum'
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
(sc: ((x: sum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_sum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
#(parse_enum_key p (sum_enum t))
(serialize_enum_key p s (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
#pc
sc
let serialize_sum
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
: Pure (serializer (parse_sum t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion)
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
let serialize_sum_eq
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
(x: sum_type t)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_sum t s sc) x == (
let tg = sum_tag_of_data t x in
serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append`
serialize (sc tg) (synth_sum_case_recip t tg x)
)))
= let tg = sum_tag_of_data t x in
synth_sum_case_injective t tg;
synth_sum_case_inverse t tg;
serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
inline_for_extraction
let make_sum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
: Tot (
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
Tot sum)
= Sum key repr e data tag_of_data
let synth_case_recip_synth_case_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))}
synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y
)
inline_for_extraction
let make_sum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(synth_case_recip_synth_case: (
(x: key) ->
Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x))
))
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
))
: Tot sum
= make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y ->
let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) =
synth_case_recip_synth_case x in
assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y))
(fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
(* Sum with default case *)
inline_for_extraction
let dsum_type_of_tag'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(k: maybe_enum_key e)
: Type
= match k with
| Unknown _ -> type_of_unknown_tag
| Known k -> type_of_known_tag k
let synth_dsum_case'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x))))
(synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x))))
(xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
: GTot data
= let (| x, y |) = xy in
match x with
| Unknown x -> synth_unknown_case x y
| Known x -> synth_known_case x y
let synth_dsum_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(y: data)
: GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
= let tg = tag_of_data y in
(| tg, synth_case_recip tg y |)
noeq
type dsum =
| DSum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (maybe_enum_key e))) ->
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
inline_for_extraction
let dsum_key_type (t: dsum) : Tot eqtype =
match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let dsum_repr_type (t: dsum) : Tot eqtype =
match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
inline_for_extraction
let dsum_key (t: dsum) : Tot Type =
maybe_enum_key (dsum_enum t)
inline_for_extraction
let dsum_known_key (t: dsum) : Tot Type =
enum_key (dsum_enum t)
inline_for_extraction
let dsum_unknown_key (t: dsum) : Tot Type =
unknown_enum_repr (dsum_enum t)
inline_for_extraction
let dsum_type (t: dsum) : Tot Type =
//NS: this was rewritten from `let DSum ... data .. = t in data`
//to workaround a glitch in desugaring the above, which introduces
//an additional, unreduced let binding for extraction
match t with
| DSum _ _ _ data _ _ _ _ _ _ _ -> data
inline_for_extraction
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) =
match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
inline_for_extraction
let dsum_cases (t: dsum) (x: dsum_key t) : Type =
refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x
inline_for_extraction
let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) =
match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) ->
type_of_known_tag
inline_for_extraction
let dsum_type_of_unknown_tag (t: dsum) : Tot Type =
match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) ->
type_of_unknown_tag
inline_for_extraction
let dsum_type_of_tag (t: dsum) =
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let weaken_parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k' : parser_kind)
: Tot parser_kind
= let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in
glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else k'
) (List.Tot.map fst (dsum_enum s)) `glb` k'
let weaken_parse_dsum_cases_kind'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k' : parser_kind)
(p: parser k' (dsum_type_of_unknown_tag s))
: Tot parser_kind
= weaken_parse_dsum_cases_kind s f k'
inline_for_extraction
let synth_dsum_case
(s: dsum)
: Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
= match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
inline_for_extraction
let synth_dsum_case_recip
(s: dsum)
: Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
= match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
let synth_dsum_case_injective
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_injective (synth_dsum_case s x))
= let f
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(requires (synth_dsum_case s x y1 == synth_dsum_case s x y2))
(ensures (y1 == y2))
= let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) =
DSum?.synth_case_recip_synth_case s x y1
in
let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) =
DSum?.synth_case_recip_synth_case s x y2
in
// FIXME: WHY WHY WHY is this assert necessary?
assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2);
()
in
let g
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2)
= Classical.move_requires (f y1) y2
in
Classical.forall_intro_2 g
let parse_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x')))
| Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
let parse_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
= synth_dsum_case_injective s x;
parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
let parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot parser_kind
= match x with
| Known k -> dfst (f k)
| _ -> k
let parse_dsum_type_of_tag'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x'))
| Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
let parse_dsum_cases'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
= synth_dsum_case_injective s x;
match x with
| Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
| Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
let parse_dsum_cases_eq'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
(input: bytes)
: Lemma
(parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
= synth_dsum_case_injective s x;
match x with
| Known x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input;
parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input
| Unknown x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input;
parse_synth_eq g (synth_dsum_case s (Unknown x')) input
let parse_dsum'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(#k: parser_kind)
(pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
: Tot (parser (and_then_kind kt k) (dsum_type t))
= parse_tagged_union
#kt
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_dsum_kind
(kt: parser_kind)
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k: parser_kind)
: Tot parser_kind
= and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
let parse_dsum
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag t))
: Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
= parse_dsum' t p (parse_dsum_cases t f g) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Sum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: LowParse.Spec.Sum.dsum ->
p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) ->
f:
(x: LowParse.Spec.Sum.dsum_known_key t
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) ->
g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input ==
(match LowParse.Spec.Base.parse p input with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k' consumed_k) ->
let k = LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.dsum_enum t) k' in
let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in
(match LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_cases t f g k) input_k with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) ->
FStar.Pervasives.Native.Some (x, consumed_k + consumed_x))
<:
FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t *
LowParse.Spec.Base.consumed_length input))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Sum.dsum",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Sum.dsum_repr_type",
"LowParse.Spec.Sum.dsum_known_key",
"Prims.dtuple2",
"LowParse.Spec.Sum.dsum_type_of_known_tag",
"LowParse.Spec.Sum.dsum_type_of_unknown_tag",
"LowParse.Bytes.bytes",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Sum.dsum_key_type",
"LowParse.Spec.Sum.dsum_enum",
"LowParse.Spec.Enum.maybe_enum_key_of_repr",
"Prims.unit",
"LowParse.Spec.Combinators.parse_tagged_union_eq",
"LowParse.Spec.Sum.dsum_key",
"LowParse.Spec.Enum.parse_maybe_enum_key",
"LowParse.Spec.Sum.dsum_type",
"LowParse.Spec.Sum.dsum_tag_of_data",
"LowParse.Spec.Sum.weaken_parse_dsum_cases_kind",
"LowParse.Spec.Sum.parse_dsum_cases",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Sum.parse_dsum",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Sum.dsum_cases",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x))) =
| parse_tagged_union_eq #(kt)
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
(parse_dsum_cases t f g)
input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input | false |
LowParse.Spec.Sum.fst | LowParse.Spec.Sum.parse_dsum_eq3 | val parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) | val parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) | let parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input | {
"file_name": "src/lowparse/LowParse.Spec.Sum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 838,
"start_col": 0,
"start_line": 818
} | module LowParse.Spec.Sum
include LowParse.Spec.Enum
module Seq = FStar.Seq
let synth_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: data)
: GTot (type_of_tag (tag_of_data x))
= synth_case_recip (tag_of_data x) x
noeq
type sum =
| Sum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (enum_key e))) ->
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
sum
inline_for_extraction
let sum_key_type (t: sum) : Tot eqtype =
match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let sum_repr_type (t: sum) : Tot eqtype =
match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
inline_for_extraction
let sum_key (t: sum) : Tot Type =
enum_key (sum_enum t)
inline_for_extraction
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t)
(requires True)
(ensures (fun k' -> k' == (k <: sum_key_type t)))
= k
inline_for_extraction
let sum_type (t: sum) : Tot Type =
match t with
| Sum _ _ _ data _ _ _ _ _ _ -> data
inline_for_extraction
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) =
match t with
| Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
inline_for_extraction
let sum_cases (t: sum) (x: sum_key t) : Type =
refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x
inline_for_extraction
let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type =
match t with
| Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag
let weaken_parse_cases_kind
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
: Tot parser_kind
= let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in
glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else default_parser_kind
) (List.Tot.map fst (sum_enum s))
inline_for_extraction
let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) =
match s with
| Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
(synth_injective (synth_sum_case s k))
= Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
let parse_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
= synth_sum_case_injective s x;
weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
let parse_sum_cases_eq
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with
| None -> None
| Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
))
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
let parse_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (dfst (f x)) (sum_cases s x))
=
synth_sum_case_injective s x;
dsnd (f x) `parse_synth` synth_sum_case s x
let parse_sum_cases_eq'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input;
parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
let parse_sum'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(#k: parser_kind)
(pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
: Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
= parse_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_sum_kind
(kt: parser_kind)
(t: sum)
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
let parse_sum
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot (parser (parse_sum_kind kt t pc) (sum_type t))
= parse_sum' t p (parse_sum_cases t pc)
let parse_sum_eq'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match
// parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k
parse (parse_sum_cases' t pc k) input_k
with
| None -> None
| Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
(parse_sum_cases t pc)
(parse_enum_key p (sum_enum t))
(fun input -> ())
(fun k -> dfst (pc k))
(parse_sum_cases' t pc)
(fun k input -> parse_sum_cases_eq' t pc k input)
input
let parse_sum_eq
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_sum_eq' t p pc input;
match parse (parse_enum_key p (sum_enum t)) input with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_sum_case_injective t k;
parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
let parse_sum_eq''
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
let k = maybe_enum_key_of_repr (sum_enum t) k' in
begin match k with
| Known k ->
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
| _ -> None
end
))
= parse_sum_eq t p pc input;
parse_enum_key_eq p (sum_enum t) input
inline_for_extraction
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) ->
synth_case_recip k x
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
(synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
= Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
let serialize_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases' s f x))
= synth_sum_case_injective s x;
synth_sum_case_inverse s x;
(serialize_synth
_
(synth_sum_case s x)
(sr x)
(synth_sum_case_recip s x)
()
)
let serialize_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases s f x))
= Classical.forall_intro (parse_sum_cases_eq' s f x);
serialize_ext
(parse_sum_cases' s f x)
(serialize_sum_cases' s f sr x)
(parse_sum_cases s f x)
let serialize_sum'
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
(sc: ((x: sum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_sum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
#(parse_enum_key p (sum_enum t))
(serialize_enum_key p s (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
#pc
sc
let serialize_sum
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
: Pure (serializer (parse_sum t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion)
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
let serialize_sum_eq
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
(x: sum_type t)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_sum t s sc) x == (
let tg = sum_tag_of_data t x in
serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append`
serialize (sc tg) (synth_sum_case_recip t tg x)
)))
= let tg = sum_tag_of_data t x in
synth_sum_case_injective t tg;
synth_sum_case_inverse t tg;
serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
inline_for_extraction
let make_sum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
: Tot (
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
Tot sum)
= Sum key repr e data tag_of_data
let synth_case_recip_synth_case_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))}
synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y
)
inline_for_extraction
let make_sum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(synth_case_recip_synth_case: (
(x: key) ->
Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x))
))
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
))
: Tot sum
= make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y ->
let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) =
synth_case_recip_synth_case x in
assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y))
(fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
(* Sum with default case *)
inline_for_extraction
let dsum_type_of_tag'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(k: maybe_enum_key e)
: Type
= match k with
| Unknown _ -> type_of_unknown_tag
| Known k -> type_of_known_tag k
let synth_dsum_case'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x))))
(synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x))))
(xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
: GTot data
= let (| x, y |) = xy in
match x with
| Unknown x -> synth_unknown_case x y
| Known x -> synth_known_case x y
let synth_dsum_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(y: data)
: GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
= let tg = tag_of_data y in
(| tg, synth_case_recip tg y |)
noeq
type dsum =
| DSum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (maybe_enum_key e))) ->
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
inline_for_extraction
let dsum_key_type (t: dsum) : Tot eqtype =
match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let dsum_repr_type (t: dsum) : Tot eqtype =
match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
inline_for_extraction
let dsum_key (t: dsum) : Tot Type =
maybe_enum_key (dsum_enum t)
inline_for_extraction
let dsum_known_key (t: dsum) : Tot Type =
enum_key (dsum_enum t)
inline_for_extraction
let dsum_unknown_key (t: dsum) : Tot Type =
unknown_enum_repr (dsum_enum t)
inline_for_extraction
let dsum_type (t: dsum) : Tot Type =
//NS: this was rewritten from `let DSum ... data .. = t in data`
//to workaround a glitch in desugaring the above, which introduces
//an additional, unreduced let binding for extraction
match t with
| DSum _ _ _ data _ _ _ _ _ _ _ -> data
inline_for_extraction
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) =
match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
inline_for_extraction
let dsum_cases (t: dsum) (x: dsum_key t) : Type =
refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x
inline_for_extraction
let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) =
match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) ->
type_of_known_tag
inline_for_extraction
let dsum_type_of_unknown_tag (t: dsum) : Tot Type =
match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) ->
type_of_unknown_tag
inline_for_extraction
let dsum_type_of_tag (t: dsum) =
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let weaken_parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k' : parser_kind)
: Tot parser_kind
= let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in
glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else k'
) (List.Tot.map fst (dsum_enum s)) `glb` k'
let weaken_parse_dsum_cases_kind'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k' : parser_kind)
(p: parser k' (dsum_type_of_unknown_tag s))
: Tot parser_kind
= weaken_parse_dsum_cases_kind s f k'
inline_for_extraction
let synth_dsum_case
(s: dsum)
: Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
= match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
inline_for_extraction
let synth_dsum_case_recip
(s: dsum)
: Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
= match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
let synth_dsum_case_injective
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_injective (synth_dsum_case s x))
= let f
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(requires (synth_dsum_case s x y1 == synth_dsum_case s x y2))
(ensures (y1 == y2))
= let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) =
DSum?.synth_case_recip_synth_case s x y1
in
let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) =
DSum?.synth_case_recip_synth_case s x y2
in
// FIXME: WHY WHY WHY is this assert necessary?
assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2);
()
in
let g
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2)
= Classical.move_requires (f y1) y2
in
Classical.forall_intro_2 g
let parse_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x')))
| Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
let parse_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
= synth_dsum_case_injective s x;
parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
let parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot parser_kind
= match x with
| Known k -> dfst (f k)
| _ -> k
let parse_dsum_type_of_tag'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x'))
| Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
let parse_dsum_cases'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
= synth_dsum_case_injective s x;
match x with
| Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
| Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
let parse_dsum_cases_eq'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
(input: bytes)
: Lemma
(parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
= synth_dsum_case_injective s x;
match x with
| Known x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input;
parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input
| Unknown x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input;
parse_synth_eq g (synth_dsum_case s (Unknown x')) input
let parse_dsum'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(#k: parser_kind)
(pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
: Tot (parser (and_then_kind kt k) (dsum_type t))
= parse_tagged_union
#kt
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_dsum_kind
(kt: parser_kind)
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k: parser_kind)
: Tot parser_kind
= and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
let parse_dsum
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag t))
: Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
= parse_dsum' t p (parse_dsum_cases t f g)
let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
let parse_dsum_eq_
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
let parse_dsum_eq'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq_ t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match k with
| Known k' ->
begin match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
| Unknown k' ->
begin match parse g input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
end
))
= parse_dsum_eq_ t p f g input;
let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in
match j with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_dsum_case_injective t k;
begin match k with
| Known k_ ->
parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k
| Unknown k_ ->
parse_synth_eq g (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Sum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: LowParse.Spec.Sum.dsum ->
p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) ->
f:
(x: LowParse.Spec.Sum.dsum_known_key t
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) ->
g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input ==
(match LowParse.Spec.Base.parse p input with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ r consumed_k) ->
let k = LowParse.Spec.Enum.maybe_enum_key_of_repr (LowParse.Spec.Sum.dsum_enum t) r in
let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in
(match
LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum_type_of_tag' t f g k) input_k
with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) ->
FStar.Pervasives.Native.Some
(LowParse.Spec.Sum.synth_dsum_case t k x,
consumed_k + consumed_x))
<:
FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t *
LowParse.Spec.Base.consumed_length input))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Sum.dsum",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Sum.dsum_repr_type",
"LowParse.Spec.Sum.dsum_known_key",
"Prims.dtuple2",
"LowParse.Spec.Sum.dsum_type_of_known_tag",
"LowParse.Spec.Sum.dsum_type_of_unknown_tag",
"LowParse.Bytes.bytes",
"LowParse.Spec.Enum.parse_maybe_enum_key_eq",
"LowParse.Spec.Sum.dsum_key_type",
"LowParse.Spec.Sum.dsum_enum",
"Prims.unit",
"LowParse.Spec.Sum.parse_dsum_eq",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Sum.dsum_type",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Sum.parse_dsum",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Sum.dsum_type_of_tag",
"LowParse.Spec.Sum.parse_dsum_type_of_tag'",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.Spec.Sum.synth_dsum_case",
"Prims.op_Addition",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Enum.maybe_enum_key_of_repr",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) =
| parse_dsum_eq t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input | false |
LowParse.Spec.Sum.fst | LowParse.Spec.Sum.serialize_dsum_eq | val serialize_dsum_eq
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_type s)
: Lemma (requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures
(serialize (serialize_dsum s st f sr g sg) x ==
(let tg = dsum_tag_of_data s x in
(serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg)
`Seq.append`
(match tg with
| Known k -> serialize (sr k) (synth_dsum_case_recip s tg x)
| Unknown k -> serialize sg (synth_dsum_case_recip s tg x))))) | val serialize_dsum_eq
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_type s)
: Lemma (requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures
(serialize (serialize_dsum s st f sr g sg) x ==
(let tg = dsum_tag_of_data s x in
(serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg)
`Seq.append`
(match tg with
| Known k -> serialize (sr k) (synth_dsum_case_recip s tg x)
| Unknown k -> serialize sg (synth_dsum_case_recip s tg x))))) | let serialize_dsum_eq
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_type s)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_dsum s st f sr g sg) x == (
let tg = dsum_tag_of_data s x in
serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg `Seq.append` (
match tg with
| Known k -> serialize (sr k) (synth_dsum_case_recip s tg x)
| Unknown k -> serialize sg (synth_dsum_case_recip s tg x)
))))
= serialize_dsum_eq' s st f sr g sg x;
let tg = dsum_tag_of_data s x in
synth_dsum_case_injective s tg;
synth_dsum_case_inverse s tg;
serialize_synth_eq
_
(synth_dsum_case s tg)
(serialize_dsum_type_of_tag s f sr g sg tg)
(synth_dsum_case_recip s tg)
()
x | {
"file_name": "src/lowparse/LowParse.Spec.Sum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1073,
"start_col": 0,
"start_line": 1042
} | module LowParse.Spec.Sum
include LowParse.Spec.Enum
module Seq = FStar.Seq
let synth_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: data)
: GTot (type_of_tag (tag_of_data x))
= synth_case_recip (tag_of_data x) x
noeq
type sum =
| Sum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (enum_key e))) ->
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
sum
inline_for_extraction
let sum_key_type (t: sum) : Tot eqtype =
match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let sum_repr_type (t: sum) : Tot eqtype =
match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
inline_for_extraction
let sum_key (t: sum) : Tot Type =
enum_key (sum_enum t)
inline_for_extraction
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t)
(requires True)
(ensures (fun k' -> k' == (k <: sum_key_type t)))
= k
inline_for_extraction
let sum_type (t: sum) : Tot Type =
match t with
| Sum _ _ _ data _ _ _ _ _ _ -> data
inline_for_extraction
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) =
match t with
| Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
inline_for_extraction
let sum_cases (t: sum) (x: sum_key t) : Type =
refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x
inline_for_extraction
let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type =
match t with
| Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag
let weaken_parse_cases_kind
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
: Tot parser_kind
= let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in
glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else default_parser_kind
) (List.Tot.map fst (sum_enum s))
inline_for_extraction
let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) =
match s with
| Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
(synth_injective (synth_sum_case s k))
= Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
let parse_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
= synth_sum_case_injective s x;
weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
let parse_sum_cases_eq
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with
| None -> None
| Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
))
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
let parse_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (dfst (f x)) (sum_cases s x))
=
synth_sum_case_injective s x;
dsnd (f x) `parse_synth` synth_sum_case s x
let parse_sum_cases_eq'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input;
parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
let parse_sum'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(#k: parser_kind)
(pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
: Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
= parse_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_sum_kind
(kt: parser_kind)
(t: sum)
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
let parse_sum
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot (parser (parse_sum_kind kt t pc) (sum_type t))
= parse_sum' t p (parse_sum_cases t pc)
let parse_sum_eq'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match
// parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k
parse (parse_sum_cases' t pc k) input_k
with
| None -> None
| Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
(parse_sum_cases t pc)
(parse_enum_key p (sum_enum t))
(fun input -> ())
(fun k -> dfst (pc k))
(parse_sum_cases' t pc)
(fun k input -> parse_sum_cases_eq' t pc k input)
input
let parse_sum_eq
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_sum_eq' t p pc input;
match parse (parse_enum_key p (sum_enum t)) input with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_sum_case_injective t k;
parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
let parse_sum_eq''
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
let k = maybe_enum_key_of_repr (sum_enum t) k' in
begin match k with
| Known k ->
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
| _ -> None
end
))
= parse_sum_eq t p pc input;
parse_enum_key_eq p (sum_enum t) input
inline_for_extraction
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) ->
synth_case_recip k x
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
(synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
= Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
let serialize_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases' s f x))
= synth_sum_case_injective s x;
synth_sum_case_inverse s x;
(serialize_synth
_
(synth_sum_case s x)
(sr x)
(synth_sum_case_recip s x)
()
)
let serialize_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases s f x))
= Classical.forall_intro (parse_sum_cases_eq' s f x);
serialize_ext
(parse_sum_cases' s f x)
(serialize_sum_cases' s f sr x)
(parse_sum_cases s f x)
let serialize_sum'
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
(sc: ((x: sum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_sum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
#(parse_enum_key p (sum_enum t))
(serialize_enum_key p s (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
#pc
sc
let serialize_sum
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
: Pure (serializer (parse_sum t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion)
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
let serialize_sum_eq
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
(x: sum_type t)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_sum t s sc) x == (
let tg = sum_tag_of_data t x in
serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append`
serialize (sc tg) (synth_sum_case_recip t tg x)
)))
= let tg = sum_tag_of_data t x in
synth_sum_case_injective t tg;
synth_sum_case_inverse t tg;
serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
inline_for_extraction
let make_sum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
: Tot (
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
Tot sum)
= Sum key repr e data tag_of_data
let synth_case_recip_synth_case_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))}
synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y
)
inline_for_extraction
let make_sum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(synth_case_recip_synth_case: (
(x: key) ->
Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x))
))
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
))
: Tot sum
= make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y ->
let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) =
synth_case_recip_synth_case x in
assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y))
(fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
(* Sum with default case *)
inline_for_extraction
let dsum_type_of_tag'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(k: maybe_enum_key e)
: Type
= match k with
| Unknown _ -> type_of_unknown_tag
| Known k -> type_of_known_tag k
let synth_dsum_case'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x))))
(synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x))))
(xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
: GTot data
= let (| x, y |) = xy in
match x with
| Unknown x -> synth_unknown_case x y
| Known x -> synth_known_case x y
let synth_dsum_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(y: data)
: GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
= let tg = tag_of_data y in
(| tg, synth_case_recip tg y |)
noeq
type dsum =
| DSum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (maybe_enum_key e))) ->
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
inline_for_extraction
let dsum_key_type (t: dsum) : Tot eqtype =
match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let dsum_repr_type (t: dsum) : Tot eqtype =
match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
inline_for_extraction
let dsum_key (t: dsum) : Tot Type =
maybe_enum_key (dsum_enum t)
inline_for_extraction
let dsum_known_key (t: dsum) : Tot Type =
enum_key (dsum_enum t)
inline_for_extraction
let dsum_unknown_key (t: dsum) : Tot Type =
unknown_enum_repr (dsum_enum t)
inline_for_extraction
let dsum_type (t: dsum) : Tot Type =
//NS: this was rewritten from `let DSum ... data .. = t in data`
//to workaround a glitch in desugaring the above, which introduces
//an additional, unreduced let binding for extraction
match t with
| DSum _ _ _ data _ _ _ _ _ _ _ -> data
inline_for_extraction
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) =
match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
inline_for_extraction
let dsum_cases (t: dsum) (x: dsum_key t) : Type =
refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x
inline_for_extraction
let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) =
match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) ->
type_of_known_tag
inline_for_extraction
let dsum_type_of_unknown_tag (t: dsum) : Tot Type =
match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) ->
type_of_unknown_tag
inline_for_extraction
let dsum_type_of_tag (t: dsum) =
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let weaken_parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k' : parser_kind)
: Tot parser_kind
= let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in
glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else k'
) (List.Tot.map fst (dsum_enum s)) `glb` k'
let weaken_parse_dsum_cases_kind'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k' : parser_kind)
(p: parser k' (dsum_type_of_unknown_tag s))
: Tot parser_kind
= weaken_parse_dsum_cases_kind s f k'
inline_for_extraction
let synth_dsum_case
(s: dsum)
: Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
= match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
inline_for_extraction
let synth_dsum_case_recip
(s: dsum)
: Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
= match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
let synth_dsum_case_injective
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_injective (synth_dsum_case s x))
= let f
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(requires (synth_dsum_case s x y1 == synth_dsum_case s x y2))
(ensures (y1 == y2))
= let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) =
DSum?.synth_case_recip_synth_case s x y1
in
let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) =
DSum?.synth_case_recip_synth_case s x y2
in
// FIXME: WHY WHY WHY is this assert necessary?
assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2);
()
in
let g
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2)
= Classical.move_requires (f y1) y2
in
Classical.forall_intro_2 g
let parse_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x')))
| Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
let parse_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
= synth_dsum_case_injective s x;
parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
let parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot parser_kind
= match x with
| Known k -> dfst (f k)
| _ -> k
let parse_dsum_type_of_tag'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x'))
| Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
let parse_dsum_cases'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
= synth_dsum_case_injective s x;
match x with
| Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
| Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
let parse_dsum_cases_eq'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
(input: bytes)
: Lemma
(parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
= synth_dsum_case_injective s x;
match x with
| Known x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input;
parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input
| Unknown x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input;
parse_synth_eq g (synth_dsum_case s (Unknown x')) input
let parse_dsum'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(#k: parser_kind)
(pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
: Tot (parser (and_then_kind kt k) (dsum_type t))
= parse_tagged_union
#kt
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_dsum_kind
(kt: parser_kind)
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k: parser_kind)
: Tot parser_kind
= and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
let parse_dsum
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag t))
: Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
= parse_dsum' t p (parse_dsum_cases t f g)
let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
let parse_dsum_eq_
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
let parse_dsum_eq'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq_ t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match k with
| Known k' ->
begin match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
| Unknown k' ->
begin match parse g input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
end
))
= parse_dsum_eq_ t p f g input;
let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in
match j with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_dsum_case_injective t k;
begin match k with
| Known k_ ->
parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k
| Unknown k_ ->
parse_synth_eq g (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k
end
let parse_dsum_eq3
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (r, consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) r in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_type_of_tag' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input
let synth_dsum_case_inverse
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_inverse (synth_dsum_case s x) (synth_dsum_case_recip s x))
= let f
(y: refine_with_tag (dsum_tag_of_data s) (x))
: Lemma
(synth_dsum_case s x (synth_dsum_case_recip s x y) == y)
= DSum?.synth_case_synth_case_recip s y
in
Classical.forall_intro f
let serialize_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_type_of_tag s f g x))
= match x with
| Known x' ->
serialize_ext (dsnd (f x')) (sr x') (parse_dsum_type_of_tag s f g x)
| Unknown x' ->
serialize_ext g sg (parse_dsum_type_of_tag s f g x)
let serialize_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_key s)
: Tot (serializer (parse_dsum_cases s f g x))
= synth_dsum_case_injective s x;
synth_dsum_case_inverse s x;
serialize_synth
_
(synth_dsum_case s x)
(serialize_dsum_type_of_tag s f sr g sg x)
(synth_dsum_case_recip s x)
()
let serialize_dsum'
(#kt: parser_kind)
(t: dsum)
(#p: parser kt (dsum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
(sc: ((x: dsum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_dsum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(kt)
#(dsum_key t)
#(parse_maybe_enum_key p (dsum_enum t))
(serialize_maybe_enum_key p s (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
#pc
sc
let serialize_dsum
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
: Pure (serializer (parse_dsum s pt f g))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_dsum' s st #_ #(parse_dsum_cases s f g) (serialize_dsum_cases s f sr g sg)
let synth_dsum_case_recip_synth_case_known_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_known_tag x) . {:pattern (synth_case_recip (Known x) (synth_case (Known x) y))}
synth_case_recip (Known x) (synth_case (Known x) y) == y
)
let synth_dsum_case_recip_synth_case_unknown_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(x: repr)
: GTot Type0
=
list_mem x (list_map snd e) == false ==> (
forall (y: type_of_unknown_tag) . {:pattern (synth_case_recip (Unknown x) (synth_case (Unknown x) y))}
synth_case_recip (Unknown x) (synth_case (Unknown x) y) == y
)
inline_for_extraction
let make_dsum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
: Tot (
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
)
= DSum key repr e data tag_of_data
inline_for_extraction
let make_dsum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(synth_case_recip_synth_case_known: (
(x: key) ->
Tot (squash (synth_dsum_case_recip_synth_case_known_post e tag_of_data type_of_known_tag type_of_unknown_tag synth_case synth_case_recip x))
))
(synth_case_recip_synth_case_unknown: (
(x: repr) ->
Tot (squash (synth_dsum_case_recip_synth_case_unknown_post e tag_of_data type_of_known_tag type_of_unknown_tag synth_case synth_case_recip x))
))
: Tot (
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
)
= make_dsum e tag_of_data type_of_known_tag type_of_unknown_tag synth_case synth_case_recip
(fun x y ->
match x with
| Known x' ->
synth_case_recip_synth_case_known x'
| Unknown x' ->
synth_case_recip_synth_case_unknown x'
)
let serialize_dsum_eq'
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(sr: (x: dsum_known_key s) -> Tot (serializer (dsnd (f x))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_type s)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_dsum s st f sr g sg) x == (
let tg = dsum_tag_of_data s x in
serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg `Seq.append`
serialize (serialize_dsum_cases s f sr g sg tg) x
)))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Sum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.Sum.dsum ->
st: LowParse.Spec.Base.serializer pt ->
f:
(x: LowParse.Spec.Sum.dsum_known_key s
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag s x))) ->
sr:
(x: LowParse.Spec.Sum.dsum_known_key s
-> LowParse.Spec.Base.serializer (FStar.Pervasives.dsnd (f x))) ->
g: LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_unknown_tag s) ->
sg: LowParse.Spec.Base.serializer g ->
x: LowParse.Spec.Sum.dsum_type s
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind kt ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong)
(ensures
LowParse.Spec.Base.serialize (LowParse.Spec.Sum.serialize_dsum s st f sr g sg) x ==
(let tg = LowParse.Spec.Sum.dsum_tag_of_data s x in
FStar.Seq.Base.append (LowParse.Spec.Base.serialize (LowParse.Spec.Enum.serialize_maybe_enum_key
pt
st
(LowParse.Spec.Sum.dsum_enum s))
tg)
(match tg with
| LowParse.Spec.Enum.Known #_ #_ #_ k ->
LowParse.Spec.Base.serialize (sr k) (LowParse.Spec.Sum.synth_dsum_case_recip s tg x)
| LowParse.Spec.Enum.Unknown #_ #_ #_ _ ->
LowParse.Spec.Base.serialize sg (LowParse.Spec.Sum.synth_dsum_case_recip s tg x)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Sum.dsum",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Sum.dsum_repr_type",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.Sum.dsum_known_key",
"Prims.dtuple2",
"LowParse.Spec.Sum.dsum_type_of_known_tag",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Sum.dsum_type_of_unknown_tag",
"LowParse.Spec.Sum.dsum_type",
"LowParse.Spec.Combinators.serialize_synth_eq",
"LowParse.Spec.Sum.weaken_parse_dsum_cases_kind",
"LowParse.Spec.Sum.dsum_type_of_tag",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.Sum.dsum_key",
"LowParse.Spec.Sum.dsum_tag_of_data",
"LowParse.Spec.Sum.parse_dsum_type_of_tag",
"LowParse.Spec.Sum.synth_dsum_case",
"LowParse.Spec.Sum.serialize_dsum_type_of_tag",
"LowParse.Spec.Sum.synth_dsum_case_recip",
"Prims.unit",
"LowParse.Spec.Sum.synth_dsum_case_inverse",
"LowParse.Spec.Sum.synth_dsum_case_injective",
"LowParse.Spec.Sum.serialize_dsum_eq'",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.squash",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.Sum.parse_dsum_kind",
"LowParse.Spec.Sum.parse_dsum",
"LowParse.Spec.Sum.serialize_dsum",
"FStar.Seq.Base.append",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Sum.dsum_key_type",
"LowParse.Spec.Sum.dsum_enum",
"LowParse.Spec.Enum.parse_maybe_enum_key",
"LowParse.Spec.Enum.serialize_maybe_enum_key",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.unknown_enum_repr",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let serialize_dsum_eq
(#kt: parser_kind)
(s: dsum)
(#pt: parser kt (dsum_repr_type s))
(st: serializer pt)
(f: (x: dsum_known_key s -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x))))
(sr: (x: dsum_known_key s -> Tot (serializer (dsnd (f x)))))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(sg: serializer g)
(x: dsum_type s)
: Lemma (requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures
(serialize (serialize_dsum s st f sr g sg) x ==
(let tg = dsum_tag_of_data s x in
(serialize (serialize_maybe_enum_key _ st (dsum_enum s)) tg)
`Seq.append`
(match tg with
| Known k -> serialize (sr k) (synth_dsum_case_recip s tg x)
| Unknown k -> serialize sg (synth_dsum_case_recip s tg x))))) =
| serialize_dsum_eq' s st f sr g sg x;
let tg = dsum_tag_of_data s x in
synth_dsum_case_injective s tg;
synth_dsum_case_inverse s tg;
serialize_synth_eq _
(synth_dsum_case s tg)
(serialize_dsum_type_of_tag s f sr g sg tg)
(synth_dsum_case_recip s tg)
()
x | false |
ID2.fst | ID2.lift_pure_nd | val lift_pure_nd (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : repr a wp | val lift_pure_nd (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : repr a wp | let lift_pure_nd (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a wp
= elim_pure_wp_monotonicity wp;
fun _ -> f () | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 61,
"start_col": 0,
"start_line": 58
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) ()
let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f
unfold
let if_then_else_wp (#a:Type) (wp1 wp2:pure_wp a) (p:bool) : pure_wp a =
elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post))
let if_then_else (a : Type)
(wp1 wp2 : pure_wp a)
(f : repr a wp1)
(g : repr a wp2) (p : bool)
: Type
= repr a (if_then_else_wp wp1 wp2 p)
// requires to prove that
// p ==> f <: (if_then_else p f g)
// ~p ==> g <: (if_then_else p f g)
// if the effect definition fails, add lemmas for the
// above with smtpats
total
reifiable
reflectable
effect {
ID (a:Type) (wp:pure_wp a)
with { repr; return; bind; subcomp; if_then_else }
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> wp: Prims.pure_wp a -> f: (_: Prims.unit -> Prims.PURE a) -> ID2.repr a wp | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"Prims.unit",
"Prims.squash",
"ID2.sat",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"ID2.repr"
] | [] | false | false | false | false | false | let lift_pure_nd (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : repr a wp =
| elim_pure_wp_monotonicity wp;
fun _ -> f () | false |
ID2.fst | ID2.sum | val sum (l: list int) : IdT int | val sum (l: list int) : IdT int | let rec sum (l : list int) : IdT int =
match l with
| [] -> 0
| x::xs -> x + sum xs | {
"file_name": "examples/layeredeffects/ID2.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 86,
"start_col": 0,
"start_line": 83
} | module ID2
unfold
let sat (w : pure_wp 'a) : Type0 = w (fun _ -> True)
open FStar.Monotonic.Pure
let repr (a : Type u#aa) (wp : pure_wp a) : Type u#aa =
squash (sat wp) -> v:a{forall p. wp p ==> p v}
let return (a : Type) (x : a) : repr a (pure_return a x) =
fun () -> x
let bind (a b : Type)
(wp_v : pure_wp a) (wp_f: a -> pure_wp b)
(v : repr a wp_v)
(f : (x:a -> repr b (wp_f x)))
: repr b (pure_bind_wp a b wp_v wp_f)
// Fun fact: using () instead of _ below makes us
// lose the refinement and then this proof fails.
// Keep that in mind all ye who enter here.
= elim_pure_wp_monotonicity_forall ();
fun _ -> f (v ()) ()
let subcomp (a:Type)
(wp1 wp2: pure_wp a)
(f : repr a wp1)
: Pure (repr a wp2)
(requires (forall p. wp2 p ==> wp1 p))
(ensures fun _ -> True)
= f
unfold
let if_then_else_wp (#a:Type) (wp1 wp2:pure_wp a) (p:bool) : pure_wp a =
elim_pure_wp_monotonicity_forall ();
as_pure_wp (fun post -> (p ==> wp1 post) /\ ((~p) ==> wp2 post))
let if_then_else (a : Type)
(wp1 wp2 : pure_wp a)
(f : repr a wp1)
(g : repr a wp2) (p : bool)
: Type
= repr a (if_then_else_wp wp1 wp2 p)
// requires to prove that
// p ==> f <: (if_then_else p f g)
// ~p ==> g <: (if_then_else p f g)
// if the effect definition fails, add lemmas for the
// above with smtpats
total
reifiable
reflectable
effect {
ID (a:Type) (wp:pure_wp a)
with { repr; return; bind; subcomp; if_then_else }
}
let lift_pure_nd (a:Type) (wp:pure_wp a) (f:unit -> PURE a wp)
: repr a wp
= elim_pure_wp_monotonicity wp;
fun _ -> f ()
sub_effect PURE ~> ID = lift_pure_nd
// this requires using a good if_then_else, but why?
let rec count (n:nat) : ID int (as_pure_wp (fun p -> forall r. p r)) =
if n = 0 then 0 else count (n-1)
(* Checking that it's kind of usable *)
val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3))
let test_f () = 5
let test_2 () : ID int (as_pure_wp (fun p -> p 5)) = 5
let l () : int = reify (test_f ()) ()
effect Id (a:Type) (pre:pure_pre) (post:pure_post' a pre) =
ID a (as_pure_wp (fun (p:pure_post a) -> pre /\ (forall (pure_result:a). post pure_result ==> p pure_result)))
effect IdT (a:Type) = Id a True (fun _ -> True) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "ID2.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.list Prims.int -> ID2.IdT Prims.int | ID2.IdT | [] | [] | [
"Prims.list",
"Prims.int",
"Prims.op_Addition",
"ID2.sum"
] | [
"recursion"
] | false | true | false | false | false | let rec sum (l: list int) : IdT int =
| match l with
| [] -> 0
| x :: xs -> x + sum xs | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac | val tac : a: Type -> b: Type -> Type | let tac a b = a -> Tac b | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 223,
"start_col": 8,
"start_line": 223
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b))
let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f
let tac_close (a b:Type)
(wp_f:b -> tac_wp_t a)
(f:(x:b -> tac_repr a (wp_f x))) =
tac_repr a (fun ps post -> forall (x:b). wp_f x ps post)
/// default effect is Tac : meaning, unannotated TAC functions will be
/// typed as Tac a
///
/// And the bind combinator has range arguments
/// that will be provided when the effect is reified
[@@ default_effect "FStar.Tactics.Effect.Tac"; bind_has_range_args]
reflectable
effect {
TAC (a:Type) (wp:tac_wp_t a)
with { repr=tac_repr;
return=tac_return;
bind=tac_bind;
if_then_else=tac_if_then_else;
subcomp=tac_subcomp;
close = tac_close }
}
(* Hoare variant *)
effect TacH (a:Type) (pre : proofstate -> Tot Type0) (post : proofstate -> __result a -> Tot Type0) =
TAC a (fun ps post' -> pre ps /\ (forall r. post ps r ==> post' r))
(* "Total" variant *)
effect Tac (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ _ -> True))
(* Metaprograms that succeed *)
effect TacS (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ps r -> Success? r))
(* A variant that doesn't prove totality (nor type safety!) *)
effect TacF (a:Type) = TacH a (requires (fun _ -> False)) (ensures (fun _ _ -> True))
unfold
let lift_div_tac_wp (#a:Type) (wp:pure_wp a) : tac_wp_t a =
elim_pure_wp_monotonicity wp;
fun ps p -> wp (fun x -> p (Success x ps))
let lift_div_tac (a:Type) (wp:pure_wp a) (f:eqtype_as_type unit -> DIV a wp)
: tac_repr a (lift_div_tac_wp wp)
= elim_pure_wp_monotonicity wp;
fun ps -> Success (f ()) ps
sub_effect DIV ~> TAC = lift_div_tac
let get ()
: TAC proofstate (fun ps post -> post (Success ps ps))
= TAC?.reflect (fun ps -> Success ps ps)
let raise (#a:Type) (e:exn)
: TAC a (fun ps post -> post (Failed e ps))
= TAC?.reflect (fun ps -> Failed #a e ps)
/// assert p by t
val with_tactic (t : unit -> Tac unit) (p:Type u#a) : Type u#a
(* This syntactic marker will generate a goal of the shape x == ?u for
* a new unification variable ?u, and run tactic [t] to solve this goal.
* If after running [t], the uvar was solved and only trivial goals remain
* in the proofstate, then `rewrite_with_tactic t x` will be replaced
* by the solution of ?u *)
val rewrite_with_tactic (t:unit -> Tac unit) (#a:Type) (x:a) : a
(* This will run the tactic in order to (try to) produce a term of type
* t. Note that the type looks dangerous from a logical perspective. It
* should not lead to any inconsistency, however, as any time this term
* appears during typechecking, it is forced to be fully applied and the
* tactic is run. A failure of the tactic is a typechecking failure. It
* can be thought as a language construct, and not a real function. *)
val synth_by_tactic : (#t:Type) -> (unit -> Tac unit) -> Tot t
val assert_by_tactic (p:Type) (t:unit -> Tac unit)
: Pure unit
(requires (set_range_of (with_tactic t (squash p)) (range_of t)))
(ensures (fun _ -> p))
val by_tactic_seman (tau:unit -> Tac unit) (phi:Type)
: Lemma (with_tactic tau phi ==> phi)
(* One can always bypass the well-formedness of metaprograms. It does
* not matter as they are only run at typechecking time, and if they get
* stuck, the compiler will simply raise an error. *)
let assume_safe (#a:Type) (tau:unit -> TacF a) : Tac a = admit (); tau () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> Type | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | true | let tac a b =
| a -> Tac b | false |
|
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tactic | val tactic : a: Type -> Type0 | let tactic a = tac unit a | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 224,
"start_col": 8,
"start_line": 224
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b))
let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f
let tac_close (a b:Type)
(wp_f:b -> tac_wp_t a)
(f:(x:b -> tac_repr a (wp_f x))) =
tac_repr a (fun ps post -> forall (x:b). wp_f x ps post)
/// default effect is Tac : meaning, unannotated TAC functions will be
/// typed as Tac a
///
/// And the bind combinator has range arguments
/// that will be provided when the effect is reified
[@@ default_effect "FStar.Tactics.Effect.Tac"; bind_has_range_args]
reflectable
effect {
TAC (a:Type) (wp:tac_wp_t a)
with { repr=tac_repr;
return=tac_return;
bind=tac_bind;
if_then_else=tac_if_then_else;
subcomp=tac_subcomp;
close = tac_close }
}
(* Hoare variant *)
effect TacH (a:Type) (pre : proofstate -> Tot Type0) (post : proofstate -> __result a -> Tot Type0) =
TAC a (fun ps post' -> pre ps /\ (forall r. post ps r ==> post' r))
(* "Total" variant *)
effect Tac (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ _ -> True))
(* Metaprograms that succeed *)
effect TacS (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ps r -> Success? r))
(* A variant that doesn't prove totality (nor type safety!) *)
effect TacF (a:Type) = TacH a (requires (fun _ -> False)) (ensures (fun _ _ -> True))
unfold
let lift_div_tac_wp (#a:Type) (wp:pure_wp a) : tac_wp_t a =
elim_pure_wp_monotonicity wp;
fun ps p -> wp (fun x -> p (Success x ps))
let lift_div_tac (a:Type) (wp:pure_wp a) (f:eqtype_as_type unit -> DIV a wp)
: tac_repr a (lift_div_tac_wp wp)
= elim_pure_wp_monotonicity wp;
fun ps -> Success (f ()) ps
sub_effect DIV ~> TAC = lift_div_tac
let get ()
: TAC proofstate (fun ps post -> post (Success ps ps))
= TAC?.reflect (fun ps -> Success ps ps)
let raise (#a:Type) (e:exn)
: TAC a (fun ps post -> post (Failed e ps))
= TAC?.reflect (fun ps -> Failed #a e ps)
/// assert p by t
val with_tactic (t : unit -> Tac unit) (p:Type u#a) : Type u#a
(* This syntactic marker will generate a goal of the shape x == ?u for
* a new unification variable ?u, and run tactic [t] to solve this goal.
* If after running [t], the uvar was solved and only trivial goals remain
* in the proofstate, then `rewrite_with_tactic t x` will be replaced
* by the solution of ?u *)
val rewrite_with_tactic (t:unit -> Tac unit) (#a:Type) (x:a) : a
(* This will run the tactic in order to (try to) produce a term of type
* t. Note that the type looks dangerous from a logical perspective. It
* should not lead to any inconsistency, however, as any time this term
* appears during typechecking, it is forced to be fully applied and the
* tactic is run. A failure of the tactic is a typechecking failure. It
* can be thought as a language construct, and not a real function. *)
val synth_by_tactic : (#t:Type) -> (unit -> Tac unit) -> Tot t
val assert_by_tactic (p:Type) (t:unit -> Tac unit)
: Pure unit
(requires (set_range_of (with_tactic t (squash p)) (range_of t)))
(ensures (fun _ -> p))
val by_tactic_seman (tau:unit -> Tac unit) (phi:Type)
: Lemma (with_tactic tau phi ==> phi)
(* One can always bypass the well-formedness of metaprograms. It does
* not matter as they are only run at typechecking time, and if they get
* stuck, the compiler will simply raise an error. *)
let assume_safe (#a:Type) (tau:unit -> TacF a) : Tac a = admit (); tau () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.tac",
"Prims.unit"
] | [] | false | false | false | true | true | let tactic a =
| tac unit a | false |
|
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.lemma_aff_is_point_at_inf | val lemma_aff_is_point_at_inf: p:proj_point ->
Lemma (let px, py, pz = p in
is_aff_point_at_inf (to_aff_point p) == (pz = 0 || (px = 0 && py = 0))) | val lemma_aff_is_point_at_inf: p:proj_point ->
Lemma (let px, py, pz = p in
is_aff_point_at_inf (to_aff_point p) == (pz = 0 || (px = 0 && py = 0))) | let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 18,
"start_col": 0,
"start_line": 14
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.K256.PointOps.proj_point
-> FStar.Pervasives.Lemma
(ensures
(let _ = p in
(let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ px py pz = _ in
Spec.K256.PointOps.is_aff_point_at_inf (Spec.K256.PointOps.to_aff_point p) ==
(pz = 0 || px = 0 && py = 0))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.proj_point",
"Spec.K256.PointOps.felem",
"Lib.NatMod.lemma_div_mod_prime_is_zero",
"Spec.K256.PointOps.prime",
"Prims.unit",
"Spec.K256.Lemmas.prime_lemma"
] | [] | false | false | true | false | false | let lemma_aff_is_point_at_inf p =
| prime_lemma ();
let px, py, pz = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_bind_wp | val tac_bind_wp (#a #b: Type) (wp_f: tac_wp_t a) (wp_g: (a -> tac_wp_t b)) : tac_wp_t b | val tac_bind_wp (#a #b: Type) (wp_f: tac_wp_t a) (wp_g: (a -> tac_wp_t b)) : tac_wp_t b | let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps)) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 54,
"start_col": 0,
"start_line": 49
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | wp_f: FStar.Tactics.Effect.tac_wp_t a -> wp_g: (_: a -> FStar.Tactics.Effect.tac_wp_t b)
-> FStar.Tactics.Effect.tac_wp_t b | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.tac_wp_t",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"Prims.exn",
"FStar.Stubs.Tactics.Result.Failed"
] | [] | false | false | false | true | false | let tac_bind_wp (#a #b: Type) (wp_f: tac_wp_t a) (wp_g: (a -> tac_wp_t b)) : tac_wp_t b =
| fun ps post ->
wp_f ps
(function
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps)) | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_return_wp | val tac_return_wp (#a: Type) (x: a) : tac_wp_t a | val tac_return_wp (#a: Type) (x: a) : tac_wp_t a | let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 42,
"start_col": 0,
"start_line": 41
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> FStar.Tactics.Effect.tac_wp_t a | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"FStar.Stubs.Tactics.Result.Success",
"FStar.Tactics.Effect.tac_wp_t"
] | [] | false | false | false | true | false | let tac_return_wp (#a: Type) (x: a) : tac_wp_t a =
| fun ps post -> post (Success x ps) | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_wp_compact | val tac_wp_compact (a: Type) (wp: tac_wp_t a) : tac_wp_t a | val tac_wp_compact (a: Type) (wp: tac_wp_t a) : tac_wp_t a | let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 114,
"end_line": 61,
"start_col": 0,
"start_line": 59
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> wp: FStar.Tactics.Effect.tac_wp_t a -> FStar.Tactics.Effect.tac_wp_t a | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.tac_wp_t",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"Prims.logical",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.guard_free"
] | [] | false | false | false | true | false | let tac_wp_compact (a: Type) (wp: tac_wp_t a) : tac_wp_t a =
| fun ps post ->
forall (k: (__result a -> Type0)).
(forall (r: __result a). {:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_subcomp | val tac_subcomp (a: Type) (wp_f wp_g: tac_wp_t a) (f: tac_repr a wp_f)
: Pure (tac_repr a wp_g) (requires forall ps p. wp_g ps p ==> wp_f ps p) (ensures fun _ -> True) | val tac_subcomp (a: Type) (wp_f wp_g: tac_wp_t a) (f: tac_repr a wp_f)
: Pure (tac_repr a wp_g) (requires forall ps p. wp_g ps p ==> wp_f ps p) (ensures fun _ -> True) | let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 131,
"start_col": 0,
"start_line": 124
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
wp_f: FStar.Tactics.Effect.tac_wp_t a ->
wp_g: FStar.Tactics.Effect.tac_wp_t a ->
f: FStar.Tactics.Effect.tac_repr a wp_f
-> Prims.Pure (FStar.Tactics.Effect.tac_repr a wp_g) | Prims.Pure | [] | [] | [
"FStar.Tactics.Effect.tac_wp_t",
"FStar.Tactics.Effect.tac_repr",
"Prims.l_Forall",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"Prims.l_imp",
"Prims.l_True"
] | [] | false | false | false | false | false | let tac_subcomp (a: Type) (wp_f wp_g: tac_wp_t a) (f: tac_repr a wp_f)
: Pure (tac_repr a wp_g) (requires forall ps p. wp_g ps p ==> wp_f ps p) (ensures fun _ -> True) =
| f | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_repr | val tac_repr : a: Type -> wp: FStar.Tactics.Effect.tac_wp_t a -> Type0 | let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0)) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 38,
"start_col": 0,
"start_line": 37
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> wp: FStar.Tactics.Effect.tac_wp_t a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.tac_wp_t",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"FStar.Monotonic.Pure.as_pure_wp"
] | [] | false | false | false | true | true | let tac_repr (a: Type) (wp: tac_wp_t a) =
| ps0: proofstate -> DIV (__result a) (as_pure_wp (wp ps0)) | false |
|
CSL.Semantics.fst | CSL.Semantics.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": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 324,
"start_col": 0,
"start_line": 315
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"FStar.Calc.calc_finish",
"CSL.Semantics.__proj__Mkst0__item__equals",
"CSL.Semantics.__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",
"CSL.Semantics.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 |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_return | val tac_return (a: Type) (x: a) : tac_repr a (tac_return_wp x) | val tac_return (a: Type) (x: a) : tac_repr a (tac_return_wp x) | let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 46,
"start_col": 0,
"start_line": 45
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> FStar.Tactics.Effect.tac_repr a (FStar.Tactics.Effect.tac_return_wp x) | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.Success",
"FStar.Stubs.Tactics.Result.__result",
"FStar.Tactics.Effect.tac_repr",
"FStar.Tactics.Effect.tac_return_wp"
] | [] | false | false | false | false | false | let tac_return (a: Type) (x: a) : tac_repr a (tac_return_wp x) =
| fun (s: proofstate) -> Success x s | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_close | val tac_close : a: Type ->
b: Type ->
wp_f: (_: b -> FStar.Tactics.Effect.tac_wp_t a) ->
f: (x: b -> FStar.Tactics.Effect.tac_repr a (wp_f x))
-> Type0 | let tac_close (a b:Type)
(wp_f:b -> tac_wp_t a)
(f:(x:b -> tac_repr a (wp_f x))) =
tac_repr a (fun ps post -> forall (x:b). wp_f x ps post) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 137,
"start_col": 0,
"start_line": 133
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b))
let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
wp_f: (_: b -> FStar.Tactics.Effect.tac_wp_t a) ->
f: (x: b -> FStar.Tactics.Effect.tac_repr a (wp_f x))
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.tac_wp_t",
"FStar.Tactics.Effect.tac_repr",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"Prims.l_Forall",
"Prims.logical"
] | [] | false | false | false | false | true | let tac_close (a b: Type) (wp_f: (b -> tac_wp_t a)) (f: (x: b -> tac_repr a (wp_f x))) =
| tac_repr a (fun ps post -> forall (x: b). wp_f x ps post) | false |
|
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.tac_if_then_else_wp | val tac_if_then_else_wp (#a: Type) (wp_then wp_else: tac_wp_t a) (b: bool) : tac_wp_t a | val tac_if_then_else_wp (#a: Type) (wp_then wp_else: tac_wp_t a) (b: bool) : tac_wp_t a | let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 113,
"start_col": 0,
"start_line": 110
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
wp_then: FStar.Tactics.Effect.tac_wp_t a ->
wp_else: FStar.Tactics.Effect.tac_wp_t a ->
b: Prims.bool
-> FStar.Tactics.Effect.tac_wp_t a | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.tac_wp_t",
"Prims.bool",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.l_not",
"Prims.logical"
] | [] | false | false | false | true | false | let tac_if_then_else_wp (#a: Type) (wp_then wp_else: tac_wp_t a) (b: bool) : tac_wp_t a =
| fun ps post -> (b ==> wp_then ps post) /\ ((~b) ==> wp_else ps post) | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.raise | val raise (#a: Type) (e: exn) : TAC a (fun ps post -> post (Failed e ps)) | val raise (#a: Type) (e: exn) : TAC a (fun ps post -> post (Failed e ps)) | let raise (#a:Type) (e:exn)
: TAC a (fun ps post -> post (Failed e ps))
= TAC?.reflect (fun ps -> Failed #a e ps) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 188,
"start_col": 0,
"start_line": 186
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b))
let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f
let tac_close (a b:Type)
(wp_f:b -> tac_wp_t a)
(f:(x:b -> tac_repr a (wp_f x))) =
tac_repr a (fun ps post -> forall (x:b). wp_f x ps post)
/// default effect is Tac : meaning, unannotated TAC functions will be
/// typed as Tac a
///
/// And the bind combinator has range arguments
/// that will be provided when the effect is reified
[@@ default_effect "FStar.Tactics.Effect.Tac"; bind_has_range_args]
reflectable
effect {
TAC (a:Type) (wp:tac_wp_t a)
with { repr=tac_repr;
return=tac_return;
bind=tac_bind;
if_then_else=tac_if_then_else;
subcomp=tac_subcomp;
close = tac_close }
}
(* Hoare variant *)
effect TacH (a:Type) (pre : proofstate -> Tot Type0) (post : proofstate -> __result a -> Tot Type0) =
TAC a (fun ps post' -> pre ps /\ (forall r. post ps r ==> post' r))
(* "Total" variant *)
effect Tac (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ _ -> True))
(* Metaprograms that succeed *)
effect TacS (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ps r -> Success? r))
(* A variant that doesn't prove totality (nor type safety!) *)
effect TacF (a:Type) = TacH a (requires (fun _ -> False)) (ensures (fun _ _ -> True))
unfold
let lift_div_tac_wp (#a:Type) (wp:pure_wp a) : tac_wp_t a =
elim_pure_wp_monotonicity wp;
fun ps p -> wp (fun x -> p (Success x ps))
let lift_div_tac (a:Type) (wp:pure_wp a) (f:eqtype_as_type unit -> DIV a wp)
: tac_repr a (lift_div_tac_wp wp)
= elim_pure_wp_monotonicity wp;
fun ps -> Success (f ()) ps
sub_effect DIV ~> TAC = lift_div_tac
let get ()
: TAC proofstate (fun ps post -> post (Success ps ps))
= TAC?.reflect (fun ps -> Success ps ps) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Prims.exn -> FStar.Tactics.Effect.TAC a | FStar.Tactics.Effect.TAC | [] | [] | [
"Prims.exn",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.Failed",
"FStar.Stubs.Tactics.Result.__result"
] | [] | false | true | false | false | false | let raise (#a: Type) (e: exn) : TAC a (fun ps post -> post (Failed e ps)) =
| TAC?.reflect (fun ps -> Failed #a e ps) | false |
CSL.Semantics.fst | CSL.Semantics.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": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 305,
"start_col": 0,
"start_line": 293
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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))
= () | {
"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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"FStar.Calc.calc_finish",
"CSL.Semantics.__proj__Mkst0__item__equals",
"CSL.Semantics.__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 |
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.lemma_proj_aff_id | val lemma_proj_aff_id (p:aff_point) :
Lemma (to_aff_point (to_proj_point p) == p) | val lemma_proj_aff_id (p:aff_point) :
Lemma (to_aff_point (to_proj_point p) == p) | let lemma_proj_aff_id p =
let (px, py) = p in
let (pX, pY, pZ) = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let (rx, ry) = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY) | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 29,
"start_col": 0,
"start_line": 21
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime)
let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures Spec.K256.PointOps.to_aff_point (Spec.K256.PointOps.to_proj_point p) == p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.aff_point",
"Spec.K256.PointOps.felem",
"Prims._assert",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.unit",
"Lib.NatMod.lemma_div_mod_prime_one",
"Spec.K256.PointOps.prime",
"Spec.K256.PointOps.op_Slash_Percent",
"Spec.K256.PointOps.to_aff_point",
"FStar.Pervasives.Native.Mktuple3",
"Spec.K256.PointOps.one",
"Spec.K256.PointOps.proj_point",
"Spec.K256.PointOps.to_proj_point"
] | [] | false | false | true | false | false | let lemma_proj_aff_id p =
| let px, py = p in
let pX, pY, pZ = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let rx, ry = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY) | false |
CSL.Semantics.fst | CSL.Semantics.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": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 313,
"start_col": 0,
"start_line": 307
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"FStar.Calc.calc_finish",
"CSL.Semantics.__proj__Mkst0__item__equals",
"CSL.Semantics.__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",
"CSL.Semantics.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 |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.lift_div_tac | val lift_div_tac (a: Type) (wp: pure_wp a) (f: (eqtype_as_type unit -> DIV a wp))
: tac_repr a (lift_div_tac_wp wp) | val lift_div_tac (a: Type) (wp: pure_wp a) (f: (eqtype_as_type unit -> DIV a wp))
: tac_repr a (lift_div_tac_wp wp) | let lift_div_tac (a:Type) (wp:pure_wp a) (f:eqtype_as_type unit -> DIV a wp)
: tac_repr a (lift_div_tac_wp wp)
= elim_pure_wp_monotonicity wp;
fun ps -> Success (f ()) ps | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 31,
"end_line": 178,
"start_col": 0,
"start_line": 175
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b))
let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f
let tac_close (a b:Type)
(wp_f:b -> tac_wp_t a)
(f:(x:b -> tac_repr a (wp_f x))) =
tac_repr a (fun ps post -> forall (x:b). wp_f x ps post)
/// default effect is Tac : meaning, unannotated TAC functions will be
/// typed as Tac a
///
/// And the bind combinator has range arguments
/// that will be provided when the effect is reified
[@@ default_effect "FStar.Tactics.Effect.Tac"; bind_has_range_args]
reflectable
effect {
TAC (a:Type) (wp:tac_wp_t a)
with { repr=tac_repr;
return=tac_return;
bind=tac_bind;
if_then_else=tac_if_then_else;
subcomp=tac_subcomp;
close = tac_close }
}
(* Hoare variant *)
effect TacH (a:Type) (pre : proofstate -> Tot Type0) (post : proofstate -> __result a -> Tot Type0) =
TAC a (fun ps post' -> pre ps /\ (forall r. post ps r ==> post' r))
(* "Total" variant *)
effect Tac (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ _ -> True))
(* Metaprograms that succeed *)
effect TacS (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ps r -> Success? r))
(* A variant that doesn't prove totality (nor type safety!) *)
effect TacF (a:Type) = TacH a (requires (fun _ -> False)) (ensures (fun _ _ -> True))
unfold
let lift_div_tac_wp (#a:Type) (wp:pure_wp a) : tac_wp_t a =
elim_pure_wp_monotonicity wp;
fun ps p -> wp (fun x -> p (Success x ps)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
wp: Prims.pure_wp a ->
f: (_: FStar.Pervasives.eqtype_as_type Prims.unit -> FStar.Pervasives.DIV a)
-> FStar.Tactics.Effect.tac_repr a (FStar.Tactics.Effect.lift_div_tac_wp wp) | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"FStar.Pervasives.eqtype_as_type",
"Prims.unit",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.Success",
"FStar.Stubs.Tactics.Result.__result",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"FStar.Tactics.Effect.tac_repr",
"FStar.Tactics.Effect.lift_div_tac_wp"
] | [] | false | false | false | false | false | let lift_div_tac (a: Type) (wp: pure_wp a) (f: (eqtype_as_type unit -> DIV a wp))
: tac_repr a (lift_div_tac_wp wp) =
| elim_pure_wp_monotonicity wp;
fun ps -> Success (f ()) ps | false |
CSL.Semantics.fst | CSL.Semantics.preserves_frame_star_left | val preserves_frame_star_left (#st: st) (pre post: st.hprop) (m0 m1: st.mem) (frame: st.hprop)
: Lemma (requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1) | val preserves_frame_star_left (#st: st) (pre post: st.hprop) (m0 m1: st.mem) (frame: st.hprop)
: Lemma (requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1) | let preserves_frame_star_left (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()]
= commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext
(st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
() | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 443,
"start_col": 0,
"start_line": 421
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#pop-options
#push-options "--z3rlimit 40 --warn_error -271"
let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
() | {
"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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pre: Mkst0?.hprop st ->
post: Mkst0?.hprop st ->
m0: Mkst0?.mem st ->
m1: Mkst0?.mem st ->
frame: Mkst0?.hprop st
-> FStar.Pervasives.Lemma (requires CSL.Semantics.preserves_frame pre post m0 m1)
(ensures
CSL.Semantics.preserves_frame (Mkst0?.star st frame pre) (Mkst0?.star st frame post) m0 m1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.__proj__Mkst0__item__mem",
"Prims.unit",
"CSL.Semantics.__proj__Mkst0__item__interp",
"CSL.Semantics.__proj__Mkst0__item__star",
"CSL.Semantics.__proj__Mkst0__item__invariant",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"CSL.Semantics.apply_interp_ext",
"CSL.Semantics.commute_assoc_star_right",
"CSL.Semantics.preserves_frame"
] | [] | false | false | true | false | false | let preserves_frame_star_left (#st: st) (pre post: st.hprop) (m0 m1: st.mem) (frame: st.hprop)
: Lemma (requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1) =
| let aux (frame': st.hprop)
: Lemma
(requires st.interp ((st.invariant m0) `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures st.interp ((st.invariant m1) `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()] =
commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext ((st.invariant m0) `st.star` ((frame `st.star` pre) `st.star` frame'))
((st.invariant m0) `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext ((st.invariant m1) `st.star` (post `st.star` (frame `st.star` frame')))
((st.invariant m1) `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
() | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.lift_div_tac_wp | val lift_div_tac_wp (#a: Type) (wp: pure_wp a) : tac_wp_t a | val lift_div_tac_wp (#a: Type) (wp: pure_wp a) : tac_wp_t a | let lift_div_tac_wp (#a:Type) (wp:pure_wp a) : tac_wp_t a =
elim_pure_wp_monotonicity wp;
fun ps p -> wp (fun x -> p (Success x ps)) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 173,
"start_col": 0,
"start_line": 171
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b))
let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f
let tac_close (a b:Type)
(wp_f:b -> tac_wp_t a)
(f:(x:b -> tac_repr a (wp_f x))) =
tac_repr a (fun ps post -> forall (x:b). wp_f x ps post)
/// default effect is Tac : meaning, unannotated TAC functions will be
/// typed as Tac a
///
/// And the bind combinator has range arguments
/// that will be provided when the effect is reified
[@@ default_effect "FStar.Tactics.Effect.Tac"; bind_has_range_args]
reflectable
effect {
TAC (a:Type) (wp:tac_wp_t a)
with { repr=tac_repr;
return=tac_return;
bind=tac_bind;
if_then_else=tac_if_then_else;
subcomp=tac_subcomp;
close = tac_close }
}
(* Hoare variant *)
effect TacH (a:Type) (pre : proofstate -> Tot Type0) (post : proofstate -> __result a -> Tot Type0) =
TAC a (fun ps post' -> pre ps /\ (forall r. post ps r ==> post' r))
(* "Total" variant *)
effect Tac (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ _ -> True))
(* Metaprograms that succeed *)
effect TacS (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ps r -> Success? r))
(* A variant that doesn't prove totality (nor type safety!) *)
effect TacF (a:Type) = TacH a (requires (fun _ -> False)) (ensures (fun _ _ -> True)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | wp: Prims.pure_wp a -> FStar.Tactics.Effect.tac_wp_t a | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.__result",
"Prims.l_True",
"FStar.Stubs.Tactics.Result.Success",
"Prims.pure_pre",
"Prims.unit",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"FStar.Tactics.Effect.tac_wp_t"
] | [] | false | false | false | true | false | let lift_div_tac_wp (#a: Type) (wp: pure_wp a) : tac_wp_t a =
| elim_pure_wp_monotonicity wp;
fun ps p -> wp (fun x -> p (Success x ps)) | false |
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.aff_point_negate_lemma | val aff_point_negate_lemma (p:aff_point) :
Lemma (aff_point_add (aff_point_negate p) p == aff_point_at_inf) | val aff_point_negate_lemma (p:aff_point) :
Lemma (aff_point_add (aff_point_negate p) p == aff_point_at_inf) | let aff_point_negate_lemma p =
let p_neg = aff_point_negate p in
let px, py = p in
let qx, qy = p_neg in
assert (qx = px /\ qy = (-py) % prime);
assert (aff_point_add p_neg p == aff_point_at_inf) | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 42,
"start_col": 0,
"start_line": 37
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime)
let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz
let lemma_proj_aff_id p =
let (px, py) = p in
let (pX, pY, pZ) = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let (rx, ry) = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY)
let aff_point_at_inf_lemma p = ()
let aff_point_add_assoc_lemma p q s = admit()
let aff_point_add_comm_lemma p q = admit() | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Spec.K256.PointOps.aff_point_add (Spec.K256.PointOps.aff_point_negate p) p ==
Spec.K256.PointOps.aff_point_at_inf) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.aff_point",
"Spec.K256.PointOps.felem",
"Prims._assert",
"Prims.eq2",
"Spec.K256.PointOps.aff_point_add",
"Spec.K256.PointOps.aff_point_at_inf",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Minus",
"Spec.K256.PointOps.prime",
"Spec.K256.PointOps.aff_point_negate"
] | [] | false | false | true | false | false | let aff_point_negate_lemma p =
| let p_neg = aff_point_negate p in
let px, py = p in
let qx, qy = p_neg in
assert (qx = px /\ qy = (- py) % prime);
assert (aff_point_add p_neg p == aff_point_at_inf) | false |
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.ecdsa_verify_avoid_finv | val ecdsa_verify_avoid_finv: p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
(_X /% _Z % q = r) <==> ((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X))) | val ecdsa_verify_avoid_finv: p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
(_X /% _Z % q = r) <==> ((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X))) | let ecdsa_verify_avoid_finv p r =
ecdsa_verify_avoid_finv1 p r;
ecdsa_verify_avoid_finv2 p r | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 143,
"start_col": 0,
"start_line": 141
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime)
let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz
let lemma_proj_aff_id p =
let (px, py) = p in
let (pX, pY, pZ) = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let (rx, ry) = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY)
let aff_point_at_inf_lemma p = ()
let aff_point_add_assoc_lemma p q s = admit()
let aff_point_add_comm_lemma p q = admit()
let aff_point_negate_lemma p =
let p_neg = aff_point_negate p in
let px, py = p in
let qx, qy = p_neg in
assert (qx = px /\ qy = (-py) % prime);
assert (aff_point_add p_neg p == aff_point_at_inf)
let to_aff_point_at_infinity_lemma () =
let px, py = to_aff_point point_at_inf in
assert (px == zero /% zero /\ py == one /% zero);
assert (px == zero *% M.pow_mod #prime zero (prime - 2));
M.lemma_pow_mod #prime zero (prime - 2);
assert (px == zero *% (M.pow zero (prime - 2) % prime));
M.lemma_pow_zero (prime - 2);
assert (px == zero /\ py == zero)
let to_aff_point_add_lemma p q = admit()
let to_aff_point_double_lemma p = admit()
let to_aff_point_negate_lemma p =
let px, py, pz = p in
let qx, qy = to_aff_point (point_negate p) in
assert (qx == px /% pz /\ qy == (- py) % prime /% pz);
let ax, ay = aff_point_negate (to_aff_point p) in
assert (ax == px /% pz /\ ay == (- py /% pz) % prime);
let pz_inv = M.pow_mod #prime pz (prime - 2) in
calc (==) { // (-py) % prime /% pz;
((- py) % prime * pz_inv) % prime;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (- py) pz_inv prime }
(- py * pz_inv) % prime;
(==) { Math.Lemmas.neg_mul_left py pz_inv }
(- (py * pz_inv)) % prime;
(==) { Math.Lemmas.lemma_mod_sub_distr 0 (py * pz_inv) prime }
(- (py * pz_inv) % prime) % prime; // (- py /% pz) % prime;
}
//----------------------------------
val lemma_div_mod_eq_mul_mod (a b c:felem) : Lemma
(requires b <> 0)
(ensures (a *% finv b = c) == (a = c *% b))
let lemma_div_mod_eq_mul_mod a b c =
prime_lemma ();
M.lemma_div_mod_eq_mul_mod #prime a b c
val ecdsa_verify_avoid_finv1:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
(_X /% _Z % q = r) ==> ((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X)))
let ecdsa_verify_avoid_finv1 p r =
let _X, _Y, _Z = p in
let x = _X /% _Z in
assert_norm (prime < 2 * q);
assert_norm (q < prime);
if x < q then begin
Math.Lemmas.small_mod x q;
assert ((x % q = r) == (x = r));
assert (r < prime /\ _X < prime /\ _Z < prime /\ _Z <> 0);
lemma_div_mod_eq_mul_mod _X _Z r;
assert ((x % q = r) == (r *% _Z = _X));
() end
else begin
Math.Lemmas.lemma_mod_sub x q (-1);
Math.Lemmas.small_mod (x - q) q;
assert (x % q == x - q);
assert ((x % q = r) == (x = r + q));
if r + q < prime then begin
lemma_div_mod_eq_mul_mod _X _Z (r + q);
assert ((x % q = r) == (r + q < prime && (r + q) *% _Z = _X)) end
else () end
val ecdsa_verify_avoid_finv2:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X)) ==> (_X /% _Z % q = r))
let ecdsa_verify_avoid_finv2 p r =
let _X, _Y, _Z = p in
let x = _X /% _Z in
assert_norm (prime < 2 * q);
assert_norm (q < prime);
if r *% _Z = _X then begin
lemma_div_mod_eq_mul_mod _X _Z r;
Math.Lemmas.small_mod x q;
assert (r = x % q) end
else begin
if r + q < prime && (r + q) *% _Z = _X then begin
lemma_div_mod_eq_mul_mod _X _Z (r + q);
assert (r + q = x);
Math.Lemmas.small_mod (x - q) q;
Math.Lemmas.lemma_mod_sub x q (-1);
assert (r = x % q) end
else () end | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Spec.K256.PointOps.proj_point{Prims.op_Negation (Spec.K256.PointOps.is_proj_point_at_inf p)} ->
r: Prims.nat{0 < r /\ r < Spec.K256.PointOps.q}
-> FStar.Pervasives.Lemma
(ensures
(let _ = p in
(let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ _X _ _Z = _ in
_X /% _Z % Spec.K256.PointOps.q = r <==>
r *% _Z = _X ||
r + Spec.K256.PointOps.q < Spec.K256.PointOps.prime &&
(r + Spec.K256.PointOps.q) *% _Z = _X)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.proj_point",
"Prims.b2t",
"Prims.op_Negation",
"Spec.K256.PointOps.is_proj_point_at_inf",
"Prims.nat",
"Prims.l_and",
"Prims.op_LessThan",
"Spec.K256.PointOps.q",
"Spec.K256.Lemmas.ecdsa_verify_avoid_finv2",
"Prims.unit",
"Spec.K256.Lemmas.ecdsa_verify_avoid_finv1"
] | [] | true | false | true | false | false | let ecdsa_verify_avoid_finv p r =
| ecdsa_verify_avoid_finv1 p r;
ecdsa_verify_avoid_finv2 p r | false |
FStar.Tactics.Effect.fsti | FStar.Tactics.Effect.get | val get: Prims.unit -> TAC proofstate (fun ps post -> post (Success ps ps)) | val get: Prims.unit -> TAC proofstate (fun ps post -> post (Success ps ps)) | let get ()
: TAC proofstate (fun ps post -> post (Success ps ps))
= TAC?.reflect (fun ps -> Success ps ps) | {
"file_name": "ulib/FStar.Tactics.Effect.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 184,
"start_col": 0,
"start_line": 182
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Effect
open FStar.Monotonic.Pure
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.Result
(* This module is extracted, don't add any `assume val`s or extraction
* will break. (`synth_by_tactic` is fine) *)
type tac_wp_t0 (a:Type) =
proofstate -> (__result a -> Type0) -> Type0
unfold
let tac_wp_monotonic (#a:Type) (wp:tac_wp_t0 a) =
forall (ps:proofstate) (p q:__result a -> Type0).
(forall x. p x ==> q x) ==> (wp ps p ==> wp ps q)
type tac_wp_t (a:Type) = wp:tac_wp_t0 a{tac_wp_monotonic wp}
let tac_repr (a:Type) (wp:tac_wp_t a) =
ps0:proofstate -> DIV (__result a) (as_pure_wp (wp ps0))
unfold
let tac_return_wp (#a:Type) (x:a) : tac_wp_t a =
fun ps post -> post (Success x ps)
(* monadic return *)
let tac_return (a:Type) (x:a) : tac_repr a (tac_return_wp x) =
fun (s:proofstate) -> Success x s
unfold
let tac_bind_wp (#a #b:Type) (wp_f:tac_wp_t a) (wp_g:a -> tac_wp_t b) : tac_wp_t b =
fun ps post ->
wp_f ps (fun r ->
match r with
| Success x ps -> wp_g x ps post
| Failed ex ps -> post (Failed ex ps))
/// An optimization to name the continuation
unfold
let tac_wp_compact (a:Type) (wp:tac_wp_t a) : tac_wp_t a =
fun ps post ->
forall (k:__result a -> Type0). (forall (r:__result a).{:pattern (guard_free (k r))} post r ==> k r) ==> wp ps k
/// tac_bind_interleave_begin is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_begin : unit
/// We cannot verify the bind combinator, since the body of bind
/// does some operations on the proof state, with which we cannot prove
/// that the proofstate is sequenced. Two ways to fix it:
///
/// 1. We separate the "meta" proofstate s.t. range, depth, etc. from the main
/// proofstate, and then sequencing only applies to the main proofstate
///
/// 2. The pre and post of the TAC effect are just exception pre and post,
/// since we can't prove much about the proofstate anyway, as it is
/// mostly abstract
(* monadic bind *)
#push-options "--admit_smt_queries true"
let tac_bind (a:Type) (b:Type)
(wp_f:tac_wp_t a)
(wp_g:a -> tac_wp_t b)
(r1 r2:range)
(t1:tac_repr a wp_f)
(t2:(x:a -> tac_repr b (wp_g x))) : tac_repr b (tac_wp_compact b (tac_bind_wp wp_f wp_g)) =
fun ps ->
let ps = set_proofstate_range ps r1 in
let ps = incr_depth ps in
let r = t1 ps in
match r with
| Success a ps' ->
let ps' = set_proofstate_range ps' r2 in
// Force evaluation of __tracepoint q even on the interpreter
begin match tracepoint ps' with
| true -> t2 a (decr_depth ps')
end
| Failed e ps' -> Failed e ps'
#pop-options
/// tac_bind_interleave_end is an ugly hack to get interface interleaving
/// work with admit_smt_queries true for the bind combinator
val tac_bind_interleave_end : unit
unfold
let tac_if_then_else_wp (#a:Type) (wp_then:tac_wp_t a) (wp_else:tac_wp_t a) (b:bool)
: tac_wp_t a
= fun ps post -> (b ==> wp_then ps post) /\
((~ b) ==> wp_else ps post)
let tac_if_then_else (a:Type)
(wp_then:tac_wp_t a)
(wp_else:tac_wp_t a)
(f:tac_repr a wp_then)
(g:tac_repr a wp_else)
(b:bool)
: Type
= tac_repr a (tac_wp_compact a (tac_if_then_else_wp wp_then wp_else b))
let tac_subcomp (a:Type)
(wp_f:tac_wp_t a)
(wp_g:tac_wp_t a)
(f:tac_repr a wp_f)
: Pure (tac_repr a wp_g)
(requires forall ps p. wp_g ps p ==> wp_f ps p)
(ensures fun _ -> True)
= f
let tac_close (a b:Type)
(wp_f:b -> tac_wp_t a)
(f:(x:b -> tac_repr a (wp_f x))) =
tac_repr a (fun ps post -> forall (x:b). wp_f x ps post)
/// default effect is Tac : meaning, unannotated TAC functions will be
/// typed as Tac a
///
/// And the bind combinator has range arguments
/// that will be provided when the effect is reified
[@@ default_effect "FStar.Tactics.Effect.Tac"; bind_has_range_args]
reflectable
effect {
TAC (a:Type) (wp:tac_wp_t a)
with { repr=tac_repr;
return=tac_return;
bind=tac_bind;
if_then_else=tac_if_then_else;
subcomp=tac_subcomp;
close = tac_close }
}
(* Hoare variant *)
effect TacH (a:Type) (pre : proofstate -> Tot Type0) (post : proofstate -> __result a -> Tot Type0) =
TAC a (fun ps post' -> pre ps /\ (forall r. post ps r ==> post' r))
(* "Total" variant *)
effect Tac (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ _ -> True))
(* Metaprograms that succeed *)
effect TacS (a:Type) = TacH a (requires (fun _ -> True)) (ensures (fun _ps r -> Success? r))
(* A variant that doesn't prove totality (nor type safety!) *)
effect TacF (a:Type) = TacH a (requires (fun _ -> False)) (ensures (fun _ _ -> True))
unfold
let lift_div_tac_wp (#a:Type) (wp:pure_wp a) : tac_wp_t a =
elim_pure_wp_monotonicity wp;
fun ps p -> wp (fun x -> p (Success x ps))
let lift_div_tac (a:Type) (wp:pure_wp a) (f:eqtype_as_type unit -> DIV a wp)
: tac_repr a (lift_div_tac_wp wp)
= elim_pure_wp_monotonicity wp;
fun ps -> Success (f ()) ps
sub_effect DIV ~> TAC = lift_div_tac | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Stubs.Tactics.Result.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Effect.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Result",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Tactics.Effect.TAC FStar.Stubs.Tactics.Types.proofstate | FStar.Tactics.Effect.TAC | [] | [] | [
"Prims.unit",
"FStar.Stubs.Tactics.Types.proofstate",
"FStar.Stubs.Tactics.Result.Success",
"FStar.Stubs.Tactics.Result.__result"
] | [] | false | true | false | false | false | let get () : TAC proofstate (fun ps post -> post (Success ps ps)) =
| TAC?.reflect (fun ps -> Success ps ps) | false |
CSL.Semantics.fst | CSL.Semantics.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": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 338,
"start_col": 0,
"start_line": 326
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"FStar.Calc.calc_finish",
"CSL.Semantics.__proj__Mkst0__item__equals",
"CSL.Semantics.__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",
"CSL.Semantics.equals_ext_right",
"Prims.squash",
"CSL.Semantics.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 |
CSL.Semantics.fst | CSL.Semantics.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": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 503,
"start_col": 0,
"start_line": 473
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#pop-options
#push-options "--z3rlimit 40 --warn_error -271"
let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
()
let preserves_frame_star_left (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()]
= commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext
(st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
()
#pop-options
/// Lemmas for proving that in the par rules preconditions get weaker
/// and postconditions get stronger
let par_weaker_lpre_and_stronger_lpost_r (#st:st)
(preL:st.hprop) (#aL:Type) (postL:post_t st aL)
(preR:st.hprop) (#aR:Type) (postR:post_t st aR)
(next_preR:st.hprop) (next_postR:post_t st aR)
(state next_state:st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` st.invariant state) state)
(ensures
st.interp ((preL `st.star` next_preR) `st.star` st.invariant next_state) next_state)
= commute_star_right (st.invariant state) preL preR;
apply_interp_ext
(st.invariant state `st.star` (preL `st.star` preR))
(st.invariant state `st.star` (preR `st.star` preL))
state;
commute_star_right (st.invariant next_state) next_preR preL;
apply_interp_ext
(st.invariant next_state `st.star` (next_preR `st.star` preL))
(st.invariant next_state `st.star` (preL `st.star` next_preR))
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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: CSL.Semantics.post_t st aL ->
postR: CSL.Semantics.post_t st aR ->
next_postR: CSL.Semantics.post_t st aR
-> FStar.Pervasives.Lemma (requires CSL.Semantics.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"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.post_t",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.__proj__Mkst0__item__mem",
"Prims.unit",
"CSL.Semantics.__proj__Mkst0__item__interp",
"CSL.Semantics.__proj__Mkst0__item__star",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"FStar.Calc.calc_finish",
"CSL.Semantics.__proj__Mkst0__item__equals",
"FStar.Preorder.relation",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims._assert",
"CSL.Semantics.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 |
CSL.Semantics.fst | CSL.Semantics.preserves_frame_star | val preserves_frame_star (#st: st) (pre post: st.hprop) (m0 m1: st.mem) (frame: st.hprop)
: Lemma (requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1) | val preserves_frame_star (#st: st) (pre post: st.hprop) (m0 m1: st.mem) (frame: st.hprop)
: Lemma (requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1) | let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
() | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 419,
"start_col": 0,
"start_line": 397
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pre: Mkst0?.hprop st ->
post: Mkst0?.hprop st ->
m0: Mkst0?.mem st ->
m1: Mkst0?.mem st ->
frame: Mkst0?.hprop st
-> FStar.Pervasives.Lemma (requires CSL.Semantics.preserves_frame pre post m0 m1)
(ensures
CSL.Semantics.preserves_frame (Mkst0?.star st pre frame) (Mkst0?.star st post frame) m0 m1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.__proj__Mkst0__item__mem",
"Prims.unit",
"CSL.Semantics.__proj__Mkst0__item__interp",
"CSL.Semantics.__proj__Mkst0__item__star",
"CSL.Semantics.__proj__Mkst0__item__invariant",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"CSL.Semantics.apply_interp_ext",
"CSL.Semantics.assoc_star_right",
"CSL.Semantics.preserves_frame"
] | [] | false | false | true | false | false | let preserves_frame_star (#st: st) (pre post: st.hprop) (m0 m1: st.mem) (frame: st.hprop)
: Lemma (requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1) =
| let aux (frame': st.hprop)
: Lemma
(requires st.interp ((st.invariant m0) `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures st.interp ((st.invariant m1) `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()] =
assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext ((st.invariant m0) `st.star` ((pre `st.star` frame) `st.star` frame'))
((st.invariant m0) `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext ((st.invariant m1) `st.star` (post `st.star` (frame `st.star` frame')))
((st.invariant m1) `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
() | false |
Spec.Agile.HMAC.fsti | Spec.Agile.HMAC.lbytes | val lbytes : l: Prims.nat -> Type0 | let lbytes (l:nat) = b:bytes {Seq.length b = l} | {
"file_name": "specs/Spec.Agile.HMAC.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 8,
"start_col": 0,
"start_line": 8
} | module Spec.Agile.HMAC
open Spec.Hash.Definitions
open Lib.IntTypes
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Agile.HMAC.fsti"
} | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.nat -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Spec.Hash.Definitions.bytes",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Seq.Base.length",
"Lib.IntTypes.uint8"
] | [] | false | false | false | true | true | let lbytes (l: nat) =
| b: bytes{Seq.length b = l} | false |
|
CSL.Semantics.fst | CSL.Semantics.step_bind_ret_aux | val step_bind_ret_aux
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Bind? f /\ Ret? (Bind?.f f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f) | val step_bind_ret_aux
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Bind? f /\ Ret? (Bind?.f f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f) | let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f /\ Ret? (Bind?.f f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f)
= M.MSTATE?.reflect (fun m0 ->
match f with
| Bind (Ret p x) g -> Step (g x), m0) | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 41,
"end_line": 529,
"start_col": 0,
"start_line": 524
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#pop-options
#push-options "--z3rlimit 40 --warn_error -271"
let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
()
let preserves_frame_star_left (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()]
= commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext
(st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
()
#pop-options
/// Lemmas for proving that in the par rules preconditions get weaker
/// and postconditions get stronger
let par_weaker_lpre_and_stronger_lpost_r (#st:st)
(preL:st.hprop) (#aL:Type) (postL:post_t st aL)
(preR:st.hprop) (#aR:Type) (postR:post_t st aR)
(next_preR:st.hprop) (next_postR:post_t st aR)
(state next_state:st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` st.invariant state) state)
(ensures
st.interp ((preL `st.star` next_preR) `st.star` st.invariant next_state) next_state)
= commute_star_right (st.invariant state) preL preR;
apply_interp_ext
(st.invariant state `st.star` (preL `st.star` preR))
(st.invariant state `st.star` (preR `st.star` preL))
state;
commute_star_right (st.invariant next_state) next_preR preL;
apply_interp_ext
(st.invariant next_state `st.star` (next_preR `st.star` preL))
(st.invariant next_state `st.star` (preL `st.star` next_preR))
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)
(f:m st a pre post{Ret? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Ret p x = f in
Step f
let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post {Act? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Act f = f in
let x = f () in
Step (Ret post x)
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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MST",
"short_module": "M"
},
{
"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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f: CSL.Semantics.m st a pre post {Bind? f /\ Ret? (Bind?.f f)}
-> FStar.MST.MSTATE (CSL.Semantics.step_result st a) | FStar.MST.MSTATE | [] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.post_t",
"CSL.Semantics.m",
"Prims.l_and",
"Prims.b2t",
"CSL.Semantics.uu___is_Bind",
"CSL.Semantics.uu___is_Ret",
"CSL.Semantics.__proj__Bind__item__a",
"CSL.Semantics.__proj__Bind__item__pre",
"CSL.Semantics.__proj__Bind__item__post_a",
"CSL.Semantics.__proj__Bind__item__f",
"CSL.Semantics.__proj__Mkst0__item__mem",
"FStar.Pervasives.Native.Mktuple2",
"CSL.Semantics.step_result",
"FStar.Pervasives.Native.tuple2",
"CSL.Semantics.Step",
"CSL.Semantics.__proj__Mkst0__item__evolves",
"CSL.Semantics.step_req",
"CSL.Semantics.step_ens"
] | [] | false | true | false | false | false | let step_bind_ret_aux
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Bind? f /\ Ret? (Bind?.f f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f) =
| M.MSTATE?.reflect (fun m0 -> match f with | Bind (Ret p x) g -> Step (g x), m0) | false |
LowParse.Spec.Sum.fst | LowParse.Spec.Sum.parse_dsum_eq | val parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
match k with
| Known k' ->
(match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))
| Unknown k' ->
match parse g input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) | val parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
match k with
| Known k' ->
(match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))
| Unknown k' ->
match parse g input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) | let parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match k with
| Known k' ->
begin match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
| Unknown k' ->
begin match parse g input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x)
end
end
))
= parse_dsum_eq_ t p f g input;
let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in
match j with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_dsum_case_injective t k;
begin match k with
| Known k_ ->
parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_))) (synth_dsum_case t k) input_k
| Unknown k_ ->
parse_synth_eq g (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k
end | {
"file_name": "src/lowparse/LowParse.Spec.Sum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 816,
"start_col": 0,
"start_line": 776
} | module LowParse.Spec.Sum
include LowParse.Spec.Enum
module Seq = FStar.Seq
let synth_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: data)
: GTot (type_of_tag (tag_of_data x))
= synth_case_recip (tag_of_data x) x
noeq
type sum =
| Sum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (enum_key e))) ->
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
sum
inline_for_extraction
let sum_key_type (t: sum) : Tot eqtype =
match t with (Sum key _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let sum_repr_type (t: sum) : Tot eqtype =
match t with (Sum _ repr _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let sum_enum (t: sum) : Tot (enum (sum_key_type t) (sum_repr_type t)) =
match t with (Sum _ _ e _ _ _ _ _ _ _) -> e
inline_for_extraction
let sum_key (t: sum) : Tot Type =
enum_key (sum_enum t)
inline_for_extraction
let sum_key_type_of_sum_key (t: sum) (k: sum_key t) : Pure (sum_key_type t)
(requires True)
(ensures (fun k' -> k' == (k <: sum_key_type t)))
= k
inline_for_extraction
let sum_type (t: sum) : Tot Type =
match t with
| Sum _ _ _ data _ _ _ _ _ _ -> data
inline_for_extraction
let sum_tag_of_data (t: sum) : Tot ((x: sum_type t) -> Tot (sum_key t)) =
match t with
| Sum _ _ _ _ tag_of_data _ _ _ _ _ -> tag_of_data
inline_for_extraction
let sum_cases (t: sum) (x: sum_key t) : Type =
refine_with_tag #(sum_key t) #(sum_type t) (sum_tag_of_data t) x
inline_for_extraction
let sum_type_of_tag (t: sum) : (x: sum_key t) -> Type =
match t with
| Sum _ _ _ _ _ type_of_tag _ _ _ _ -> type_of_tag
let weaken_parse_cases_kind
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
: Tot parser_kind
= let keys : list (sum_key_type s) = List.Tot.map fst (sum_enum s) in
glb_list_of #(sum_key_type s) (fun (x: sum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else default_parser_kind
) (List.Tot.map fst (sum_enum s))
inline_for_extraction
let synth_sum_case (s: sum) : (k: sum_key s) -> (x: sum_type_of_tag s k) -> Tot (sum_cases s k) =
match s with
| Sum _ _ _ _ _ _ synth_case _ _ _ -> synth_case
let synth_sum_case_injective (s: sum) (k: sum_key s) : Lemma
(synth_injective (synth_sum_case s k))
= Classical.forall_intro (Sum?.synth_case_recip_synth_case s k)
let parse_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (weaken_parse_cases_kind s f) (sum_cases s x))
= synth_sum_case_injective s x;
weaken (weaken_parse_cases_kind s f) (dsnd (f x)) `parse_synth` (synth_sum_case s x)
let parse_sum_cases_eq
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == (match parse (dsnd (f x)) input with
| None -> None
| Some (y, consumed) -> Some (synth_sum_case s x y, consumed)
))
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input
let parse_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
: Tot (parser (dfst (f x)) (sum_cases s x))
=
synth_sum_case_injective s x;
dsnd (f x) `parse_synth` synth_sum_case s x
let parse_sum_cases_eq'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(x: sum_key s)
(input: bytes)
: Lemma
(parse (parse_sum_cases s f x) input == parse (parse_sum_cases' s f x) input)
= synth_sum_case_injective s x;
parse_synth_eq (weaken (weaken_parse_cases_kind s f) (dsnd (f x))) (synth_sum_case s x) input;
parse_synth_eq (dsnd (f x)) (synth_sum_case s x) input
let parse_sum'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(#k: parser_kind)
(pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
: Tot (parser (and_then_kind (parse_filter_kind kt) k) (sum_type t))
= parse_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_sum_kind
(kt: parser_kind)
(t: sum)
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot parser_kind
= and_then_kind (parse_filter_kind kt) (weaken_parse_cases_kind t pc)
let parse_sum
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
: Tot (parser (parse_sum_kind kt t pc) (sum_type t))
= parse_sum' t p (parse_sum_cases t pc)
let parse_sum_eq'
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match
// parse (synth_sum_case_injective t k; parse_synth (dsnd (pc k)) (synth_sum_case t k)) input_k
parse (parse_sum_cases' t pc k) input_k
with
| None -> None
| Some (x, consumed_x) -> Some ((x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen
#(parse_filter_kind kt)
#(sum_key t)
(parse_enum_key p (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
(parse_sum_cases t pc)
(parse_enum_key p (sum_enum t))
(fun input -> ())
(fun k -> dfst (pc k))
(parse_sum_cases' t pc)
(fun k input -> parse_sum_cases_eq' t pc k input)
input
let parse_sum_eq
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse (parse_enum_key p (sum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
))
= parse_sum_eq' t p pc input;
match parse (parse_enum_key p (sum_enum t)) input with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_sum_case_injective t k;
parse_synth_eq (dsnd (pc k)) (synth_sum_case t k) input_k
let parse_sum_eq''
(#kt: parser_kind)
(t: sum)
(p: parser kt (sum_repr_type t))
(pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(input: bytes)
: Lemma
(parse (parse_sum t p pc) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
let k = maybe_enum_key_of_repr (sum_enum t) k' in
begin match k with
| Known k ->
begin match parse (dsnd (pc k)) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((synth_sum_case t k x <: sum_type t), consumed_k + consumed_x)
end
| _ -> None
end
))
= parse_sum_eq t p pc input;
parse_enum_key_eq p (sum_enum t) input
inline_for_extraction
let synth_sum_case_recip (s: sum) (k: sum_key s) (x: sum_cases s k) : Tot (sum_type_of_tag s k) =
match s with (Sum _ _ _ _ _ _ _ synth_case_recip _ _) ->
synth_case_recip k x
let synth_sum_case_inverse (s: sum) (k: sum_key s) : Lemma
(synth_inverse (synth_sum_case s k) (synth_sum_case_recip s k))
= Classical.forall_intro (Sum?.synth_case_synth_case_recip s)
let serialize_sum_cases'
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases' s f x))
= synth_sum_case_injective s x;
synth_sum_case_inverse s x;
(serialize_synth
_
(synth_sum_case s x)
(sr x)
(synth_sum_case_recip s x)
()
)
let serialize_sum_cases
(s: sum)
(f: (x: sum_key s) -> Tot (k: parser_kind & parser k (sum_type_of_tag s x)))
(sr: (x: sum_key s) -> Tot (serializer (dsnd (f x))))
(x: sum_key s)
: Tot (serializer (parse_sum_cases s f x))
= Classical.forall_intro (parse_sum_cases_eq' s f x);
serialize_ext
(parse_sum_cases' s f x)
(serialize_sum_cases' s f sr x)
(parse_sum_cases s f x)
let serialize_sum'
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#k: parser_kind)
(#pc: ((x: sum_key t) -> Tot (parser k (sum_cases t x))))
(sc: ((x: sum_key t) -> Tot (serializer (pc x))))
: Pure (serializer (parse_sum' t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= serialize_tagged_union
#(parse_filter_kind kt)
#(sum_key t)
#(parse_enum_key p (sum_enum t))
(serialize_enum_key p s (sum_enum t))
#(sum_type t)
(sum_tag_of_data t)
#k
#pc
sc
let serialize_sum
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
: Pure (serializer (parse_sum t p pc))
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (fun _ -> True))
= // FIXME: WHY WHY WHY is implicit argument inference failing here? (i.e. introducing an eta-expansion)
serialize_sum' t s #_ #(parse_sum_cases t pc) (serialize_sum_cases t pc sc)
let serialize_sum_eq
(#kt: parser_kind)
(t: sum)
(#p: parser kt (sum_repr_type t))
(s: serializer p)
(#pc: ((x: sum_key t) -> Tot (k: parser_kind & parser k (sum_type_of_tag t x))))
(sc: ((x: sum_key t) -> Tot (serializer (dsnd (pc x)))))
(x: sum_type t)
: Lemma
(requires (kt.parser_kind_subkind == Some ParserStrong))
(ensures (
serialize (serialize_sum t s sc) x == (
let tg = sum_tag_of_data t x in
serialize (serialize_enum_key _ s (sum_enum t)) tg `Seq.append`
serialize (sc tg) (synth_sum_case_recip t tg x)
)))
= let tg = sum_tag_of_data t x in
synth_sum_case_injective t tg;
synth_sum_case_inverse t tg;
serialize_synth_eq (dsnd (pc tg)) (synth_sum_case t tg) (sc tg) (synth_sum_case_recip t tg) () x
inline_for_extraction
let make_sum
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
: Tot (
(type_of_tag: (enum_key e -> Tot Type)) ->
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k))) ->
(synth_case_recip_synth_case: (
(x: enum_key e) ->
(y: type_of_tag x) ->
Lemma
(synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Lemma
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x)
)) ->
Tot sum)
= Sum key repr e data tag_of_data
let synth_case_recip_synth_case_post
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(x: key)
: GTot Type0
=
list_mem x (list_map fst e) ==> (
forall (y: type_of_tag x) . {:pattern (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y))}
synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y
)
inline_for_extraction
let make_sum'
(#key #repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> Tot (enum_key e)))
(type_of_tag: (enum_key e -> Tot Type))
(synth_case: ((x: enum_key e) -> (y: type_of_tag x) -> Tot (refine_with_tag tag_of_data x)))
(synth_case_recip: ((k: enum_key e) -> (x: refine_with_tag tag_of_data k) -> Tot (type_of_tag k)))
(synth_case_recip_synth_case: (
(x: key) ->
Tot (squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x))
))
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
))
: Tot sum
= make_sum e tag_of_data type_of_tag synth_case synth_case_recip (fun x y ->
let sq : squash (synth_case_recip_synth_case_post e tag_of_data type_of_tag synth_case synth_case_recip x) =
synth_case_recip_synth_case x in
assert (synth_case_recip' e tag_of_data type_of_tag synth_case_recip (synth_case x y) == y))
(fun x -> let _ = synth_case_synth_case_recip x in assert (synth_case (tag_of_data x) (synth_case_recip' e tag_of_data type_of_tag synth_case_recip x) == x))
(* Sum with default case *)
inline_for_extraction
let dsum_type_of_tag'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(k: maybe_enum_key e)
: Type
= match k with
| Unknown _ -> type_of_unknown_tag
| Known k -> type_of_known_tag k
let synth_dsum_case'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_known_case: ((x: enum_key e) -> (y: type_of_known_tag x) -> Tot (refine_with_tag tag_of_data (Known x))))
(synth_unknown_case: ((x: unknown_enum_repr e) -> type_of_unknown_tag -> Tot (refine_with_tag tag_of_data (Unknown x))))
(xy: (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x))
: GTot data
= let (| x, y |) = xy in
match x with
| Unknown x -> synth_unknown_case x y
| Known x -> synth_known_case x y
let synth_dsum_case_recip'
(#key: eqtype)
(#repr: eqtype)
(e: enum key repr)
(#data: Type)
(tag_of_data: (data -> GTot (maybe_enum_key e)))
(type_of_known_tag: (enum_key e -> Tot Type))
(type_of_unknown_tag: Type)
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k)))
(y: data)
: GTot (x: maybe_enum_key e & dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x)
= let tg = tag_of_data y in
(| tg, synth_case_recip tg y |)
noeq
type dsum =
| DSum:
(key: eqtype) ->
(repr: eqtype) ->
(e: enum key repr) ->
(data: Type) ->
(tag_of_data: (data -> Tot (maybe_enum_key e))) ->
(type_of_known_tag: (enum_key e -> Tot Type)) ->
(type_of_unknown_tag: Type) ->
(synth_case: ((x: maybe_enum_key e) -> (y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) -> Tot (refine_with_tag tag_of_data x))) ->
(synth_case_recip: ((k: maybe_enum_key e) -> (refine_with_tag tag_of_data k) -> Tot (dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag k))) ->
(synth_case_recip_synth_case: (
(x: maybe_enum_key e) ->
(y: dsum_type_of_tag' e type_of_known_tag type_of_unknown_tag x) ->
Tot (squash
(synth_case_recip x (synth_case x y) == y)
)
)) ->
(synth_case_synth_case_recip: (
(x: data) ->
Tot (squash
(synth_case (tag_of_data x) (synth_case_recip (tag_of_data x) x) == x)
)
)) ->
dsum
inline_for_extraction
let dsum_key_type (t: dsum) : Tot eqtype =
match t with (DSum key _ _ _ _ _ _ _ _ _ _) -> key
inline_for_extraction
let dsum_repr_type (t: dsum) : Tot eqtype =
match t with (DSum _ repr _ _ _ _ _ _ _ _ _) -> repr
inline_for_extraction
let dsum_enum (t: dsum) : Tot (enum (dsum_key_type t) (dsum_repr_type t)) =
match t with (DSum _ _ e _ _ _ _ _ _ _ _) -> e
inline_for_extraction
let dsum_key (t: dsum) : Tot Type =
maybe_enum_key (dsum_enum t)
inline_for_extraction
let dsum_known_key (t: dsum) : Tot Type =
enum_key (dsum_enum t)
inline_for_extraction
let dsum_unknown_key (t: dsum) : Tot Type =
unknown_enum_repr (dsum_enum t)
inline_for_extraction
let dsum_type (t: dsum) : Tot Type =
//NS: this was rewritten from `let DSum ... data .. = t in data`
//to workaround a glitch in desugaring the above, which introduces
//an additional, unreduced let binding for extraction
match t with
| DSum _ _ _ data _ _ _ _ _ _ _ -> data
inline_for_extraction
let dsum_tag_of_data (t: dsum) : Tot ((x: dsum_type t) -> Tot (dsum_key t)) =
match t with (DSum _ _ _ _ tag_of_data _ _ _ _ _ _) -> tag_of_data
inline_for_extraction
let dsum_cases (t: dsum) (x: dsum_key t) : Type =
refine_with_tag #(dsum_key t) #(dsum_type t) (dsum_tag_of_data t) x
inline_for_extraction
let dsum_type_of_known_tag (t: dsum) : Tot ((k: dsum_known_key t) -> Tot Type) =
match t with (DSum _ _ _ _ _ type_of_known_tag _ _ _ _ _) ->
type_of_known_tag
inline_for_extraction
let dsum_type_of_unknown_tag (t: dsum) : Tot Type =
match t with (DSum _ _ _ _ _ _ type_of_unknown_tag _ _ _ _) ->
type_of_unknown_tag
inline_for_extraction
let dsum_type_of_tag (t: dsum) =
dsum_type_of_tag' (dsum_enum t) (dsum_type_of_known_tag t) (dsum_type_of_unknown_tag t)
let weaken_parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k' : parser_kind)
: Tot parser_kind
= let keys : list (dsum_key_type s) = List.Tot.map fst (dsum_enum s) in
glb_list_of #(dsum_key_type s) (fun (x: dsum_key_type s) ->
if List.Tot.mem x keys
then let (| k, _ |) = f x in k
else k'
) (List.Tot.map fst (dsum_enum s)) `glb` k'
let weaken_parse_dsum_cases_kind'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k' : parser_kind)
(p: parser k' (dsum_type_of_unknown_tag s))
: Tot parser_kind
= weaken_parse_dsum_cases_kind s f k'
inline_for_extraction
let synth_dsum_case
(s: dsum)
: Tot ((x: dsum_key s) -> dsum_type_of_tag s x -> Tot (refine_with_tag (dsum_tag_of_data s) x))
= match s with DSum _ _ _ _ _ _ _ synth_case _ _ _ -> synth_case
inline_for_extraction
let synth_dsum_case_recip
(s: dsum)
: Tot ((x: dsum_key s) -> refine_with_tag (dsum_tag_of_data s) x -> Tot (dsum_type_of_tag s x))
= match s with DSum _ _ _ _ _ _ _ _ synth_case_recip _ _ -> synth_case_recip
let synth_dsum_case_injective
(s: dsum)
(x: dsum_key s)
: Lemma
(synth_injective (synth_dsum_case s x))
= let f
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(requires (synth_dsum_case s x y1 == synth_dsum_case s x y2))
(ensures (y1 == y2))
= let k1 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y1) == y1) =
DSum?.synth_case_recip_synth_case s x y1
in
let k2 : squash (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2) =
DSum?.synth_case_recip_synth_case s x y2
in
// FIXME: WHY WHY WHY is this assert necessary?
assert (synth_dsum_case_recip s x (synth_dsum_case s x y2) == y2);
()
in
let g
(y1: dsum_type_of_tag s x)
(y2: dsum_type_of_tag s x)
: Lemma
(synth_dsum_case s x y1 == synth_dsum_case s x y2 ==> y1 == y2)
= Classical.move_requires (f y1) y2
in
Classical.forall_intro_2 g
let parse_dsum_type_of_tag
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)) (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x')))
| Unknown x' -> weaken (weaken_parse_dsum_cases_kind s f k) g <: parser (weaken_parse_dsum_cases_kind s f k) (dsum_type_of_tag s x)
let parse_dsum_cases
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (weaken_parse_dsum_cases_kind s f k) (dsum_cases s x))
= synth_dsum_case_injective s x;
parse_dsum_type_of_tag s f g x `parse_synth` synth_dsum_case s x
let parse_dsum_cases_kind
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot parser_kind
= match x with
| Known k -> dfst (f k)
| _ -> k
let parse_dsum_type_of_tag'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x))
= match x with
| Known x' -> coerce (parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)) (dsnd (f x'))
| Unknown x' -> g <: parser (parse_dsum_cases_kind s f g x) (dsum_type_of_tag s x)
let parse_dsum_cases'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
: Tot (parser (parse_dsum_cases_kind s f g x) (dsum_cases s x))
= synth_dsum_case_injective s x;
match x with
| Known x' -> (dsnd (f x') `parse_synth` synth_dsum_case s (Known x')) <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
| Unknown x' -> g `parse_synth` synth_dsum_case s (Unknown x') <: parser (parse_dsum_cases_kind s f g x) (dsum_cases s x)
let parse_dsum_cases_eq'
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag s))
(x: dsum_key s)
(input: bytes)
: Lemma
(parse (parse_dsum_cases s f g x) input == parse (parse_dsum_cases' s f g x) input)
= synth_dsum_case_injective s x;
match x with
| Known x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) (dsnd (f x'))) (synth_dsum_case s x) input;
parse_synth_eq (dsnd (f x')) (synth_dsum_case s (Known x')) input
| Unknown x' ->
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind s f k) g) (synth_dsum_case s x) input;
parse_synth_eq g (synth_dsum_case s (Unknown x')) input
let parse_dsum'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(#k: parser_kind)
(pc: ((x: dsum_key t) -> Tot (parser k (dsum_cases t x))))
: Tot (parser (and_then_kind kt k) (dsum_type t))
= parse_tagged_union
#kt
#(dsum_key t)
(parse_maybe_enum_key p (dsum_enum t))
#(dsum_type t)
(dsum_tag_of_data t)
#k
pc
inline_for_extraction
let parse_dsum_kind
(kt: parser_kind)
(s: dsum)
(f: (x: dsum_known_key s) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag s x)))
(k: parser_kind)
: Tot parser_kind
= and_then_kind kt (weaken_parse_dsum_cases_kind s f k)
let parse_dsum
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k: parser_kind)
(g: parser k (dsum_type_of_unknown_tag t))
: Tot (parser (parse_dsum_kind kt t f k) (dsum_type t))
= parse_dsum' t p (parse_dsum_cases t f g)
let parse_dsum_eq''
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq #(kt) #(dsum_key t) (parse_maybe_enum_key p (dsum_enum t)) #(dsum_type t) (dsum_tag_of_data t) (parse_dsum_cases t f g) input;
parse_synth_eq p (maybe_enum_key_of_repr (dsum_enum t)) input
let parse_dsum_eq_
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_tagged_union_eq_gen (parse_maybe_enum_key p (dsum_enum t)) (dsum_tag_of_data t) (parse_dsum_cases t f g) (parse_maybe_enum_key p (dsum_enum t)) (fun input -> ()) (parse_dsum_cases_kind t f g) (parse_dsum_cases' t f g) (fun tg input -> parse_dsum_cases_eq' t f g tg input) input
let parse_dsum_eq'
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t) -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x)))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input == (match parse p input with
| None -> None
| Some (k', consumed_k) ->
let k = maybe_enum_key_of_repr (dsum_enum t) k' in
let input_k = Seq.slice input consumed_k (Seq.length input) in
begin match parse (parse_dsum_cases' t f g k) input_k with
| None -> None
| Some (x, consumed_x) -> Some ((x <: dsum_type t), consumed_k + consumed_x)
end
))
= parse_dsum_eq_ t p f g input;
parse_maybe_enum_key_eq p (dsum_enum t) input | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Sum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: LowParse.Spec.Sum.dsum ->
p: LowParse.Spec.Base.parser kt (LowParse.Spec.Sum.dsum_repr_type t) ->
f:
(x: LowParse.Spec.Sum.dsum_known_key t
-> Prims.dtuple2 LowParse.Spec.Base.parser_kind
(fun k -> LowParse.Spec.Base.parser k (LowParse.Spec.Sum.dsum_type_of_known_tag t x))) ->
g: LowParse.Spec.Base.parser k' (LowParse.Spec.Sum.dsum_type_of_unknown_tag t) ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.parse (LowParse.Spec.Sum.parse_dsum t p f g) input ==
(match
LowParse.Spec.Base.parse (LowParse.Spec.Enum.parse_maybe_enum_key p
(LowParse.Spec.Sum.dsum_enum t))
input
with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ k consumed_k) ->
let input_k = FStar.Seq.Base.slice input consumed_k (FStar.Seq.Base.length input) in
(match k with
| LowParse.Spec.Enum.Known #_ #_ #_ k' ->
(match LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (f k')) input_k with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) ->
FStar.Pervasives.Native.Some
(LowParse.Spec.Sum.synth_dsum_case t k x,
consumed_k + consumed_x))
<:
FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t *
LowParse.Spec.Base.consumed_length input)
| LowParse.Spec.Enum.Unknown #_ #_ #_ _ ->
(match LowParse.Spec.Base.parse g input_k with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) ->
FStar.Pervasives.Native.Some
(LowParse.Spec.Sum.synth_dsum_case t k x,
consumed_k + consumed_x))
<:
FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t *
LowParse.Spec.Base.consumed_length input))
<:
FStar.Pervasives.Native.option (LowParse.Spec.Sum.dsum_type t *
LowParse.Spec.Base.consumed_length input))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Sum.dsum",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Sum.dsum_repr_type",
"LowParse.Spec.Sum.dsum_known_key",
"Prims.dtuple2",
"LowParse.Spec.Sum.dsum_type_of_known_tag",
"LowParse.Spec.Sum.dsum_type_of_unknown_tag",
"LowParse.Bytes.bytes",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Sum.dsum_key_type",
"LowParse.Spec.Sum.dsum_enum",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.Sum.weaken_parse_dsum_cases_kind",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.Sum.dsum_key",
"LowParse.Spec.Sum.dsum_type",
"LowParse.Spec.Sum.dsum_tag_of_data",
"LowParse.Spec.Base.weaken",
"Prims.__proj__Mkdtuple2__item___1",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Sum.synth_dsum_case",
"Prims.unit",
"LowParse.Spec.Enum.unknown_enum_repr",
"LowParse.Spec.Sum.synth_dsum_case_injective",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Enum.parse_maybe_enum_key",
"LowParse.Spec.Sum.parse_dsum_eq_",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.Spec.Sum.parse_dsum",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let parse_dsum_eq
(#kt: parser_kind)
(t: dsum)
(p: parser kt (dsum_repr_type t))
(f: (x: dsum_known_key t -> Tot (k: parser_kind & parser k (dsum_type_of_known_tag t x))))
(#k': parser_kind)
(g: parser k' (dsum_type_of_unknown_tag t))
(input: bytes)
: Lemma
(parse (parse_dsum t p f g) input ==
(match parse (parse_maybe_enum_key p (dsum_enum t)) input with
| None -> None
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
match k with
| Known k' ->
(match parse (dsnd (f k')) input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))
| Unknown k' ->
match parse g input_k with
| None -> None
| Some (x, consumed_x) ->
Some ((synth_dsum_case t k x <: dsum_type t), consumed_k + consumed_x))) =
| parse_dsum_eq_ t p f g input;
let j = parse (parse_maybe_enum_key p (dsum_enum t)) input in
match j with
| None -> ()
| Some (k, consumed_k) ->
let input_k = Seq.slice input consumed_k (Seq.length input) in
synth_dsum_case_injective t k;
match k with
| Known k_ ->
parse_synth_eq (dsnd (f k_)) (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') (dsnd (f k_)))
(synth_dsum_case t k)
input_k
| Unknown k_ ->
parse_synth_eq g (synth_dsum_case t k) input_k;
parse_synth_eq (weaken (weaken_parse_dsum_cases_kind t f k') g) (synth_dsum_case t k) input_k | false |
CSL.Semantics.fst | CSL.Semantics.step_par_ret | val step_par_ret
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: Mst (step_result st a) (step_req f) (step_ens f) | val step_par_ret
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: Mst (step_result st a) (step_req f) (step_ens f) | let step_par_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: Mst (step_result st a) (step_req f) (step_ens f)
= NMSTATE?.reflect (fun (_, n) -> step_par_ret_aux f, n) | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 583,
"start_col": 0,
"start_line": 580
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#pop-options
#push-options "--z3rlimit 40 --warn_error -271"
let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
()
let preserves_frame_star_left (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()]
= commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext
(st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
()
#pop-options
/// Lemmas for proving that in the par rules preconditions get weaker
/// and postconditions get stronger
let par_weaker_lpre_and_stronger_lpost_r (#st:st)
(preL:st.hprop) (#aL:Type) (postL:post_t st aL)
(preR:st.hprop) (#aR:Type) (postR:post_t st aR)
(next_preR:st.hprop) (next_postR:post_t st aR)
(state next_state:st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` st.invariant state) state)
(ensures
st.interp ((preL `st.star` next_preR) `st.star` st.invariant next_state) next_state)
= commute_star_right (st.invariant state) preL preR;
apply_interp_ext
(st.invariant state `st.star` (preL `st.star` preR))
(st.invariant state `st.star` (preR `st.star` preL))
state;
commute_star_right (st.invariant next_state) next_preR preL;
apply_interp_ext
(st.invariant next_state `st.star` (next_preR `st.star` preL))
(st.invariant next_state `st.star` (preL `st.star` next_preR))
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)
(f:m st a pre post{Ret? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Ret p x = f in
Step f
let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post {Act? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Act f = f in
let x = f () in
Step (Ret post x)
module M = FStar.MST
let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f /\ Ret? (Bind?.f f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f)
= M.MSTATE?.reflect (fun m0 ->
match f with
| Bind (Ret p x) g -> Step (g x), m0)
let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f /\ Ret? (Bind?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f)
= NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux f, n)
let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f})
(step:step_t)
: Mst (step_result st a) (step_req f) (step_ens f)
= match f with
| Bind (Ret _ _) _ -> step_bind_ret f
| Bind #_ #_ #_ #_ #_ #post_b f g ->
let Step #_ #_ #next_pre #next_post f = step f in
Step #_ #_ #next_pre #post_b
(Bind f (fun x -> Weaken (next_post x) _ () (g x)))
let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a)
(f:m st a pre p{Frame? f /\ Ret? (Frame?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Frame (Ret p x) frame = f in
Step (Ret (fun x -> p x `st.star` frame) x)
let step_frame (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a)
(f:m st a pre p{Frame? f})
(step:step_t)
: Mst (step_result st a) (step_req f) (step_ens f)
= match f with
| Frame (Ret _ _) _ -> step_frame_ret f
| Frame #_ #_ #f_pre #_ f frame ->
let m0 = get () in
let Step #_ #_ #next_fpre #next_fpost f = step f in
let m1 = get () in
preserves_frame_star f_pre next_fpre m0 m1 frame;
Step (Frame f frame)
let step_par_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f)
= M.MSTATE?.reflect (fun m0 ->
let Par (Ret pL xL) (Ret pR xR) = f in
Step (Ret (fun (xL, xR) -> pL xL `st.star` pR xR) (xL, xR)), 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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MST",
"short_module": "M"
},
{
"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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f: CSL.Semantics.m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}
-> CSL.Semantics.Mst (CSL.Semantics.step_result st a) | CSL.Semantics.Mst | [] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.post_t",
"CSL.Semantics.m",
"Prims.l_and",
"Prims.b2t",
"CSL.Semantics.uu___is_Par",
"CSL.Semantics.uu___is_Ret",
"CSL.Semantics.__proj__Par__item__aL",
"CSL.Semantics.__proj__Par__item__preL",
"CSL.Semantics.__proj__Par__item__postL",
"CSL.Semantics.__proj__Par__item__mL",
"CSL.Semantics.__proj__Par__item__aR",
"CSL.Semantics.__proj__Par__item__preR",
"CSL.Semantics.__proj__Par__item__postR",
"CSL.Semantics.__proj__Par__item__mR",
"FStar.Pervasives.Native.tuple2",
"FStar.NMST.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"CSL.Semantics.step_result",
"CSL.Semantics.step_par_ret_aux",
"CSL.Semantics.step_req",
"CSL.Semantics.step_ens"
] | [] | false | true | false | false | false | let step_par_ret
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: Mst (step_result st a) (step_req f) (step_ens f) =
| NMSTATE?.reflect (fun (_, n) -> step_par_ret_aux f, n) | false |
CSL.Semantics.fst | CSL.Semantics.step_bind_ret | val step_bind_ret
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Bind? f /\ Ret? (Bind?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f) | val step_bind_ret
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Bind? f /\ Ret? (Bind?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f) | let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f /\ Ret? (Bind?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f)
= NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux f, n) | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 57,
"end_line": 534,
"start_col": 0,
"start_line": 531
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#pop-options
#push-options "--z3rlimit 40 --warn_error -271"
let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
()
let preserves_frame_star_left (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()]
= commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext
(st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
()
#pop-options
/// Lemmas for proving that in the par rules preconditions get weaker
/// and postconditions get stronger
let par_weaker_lpre_and_stronger_lpost_r (#st:st)
(preL:st.hprop) (#aL:Type) (postL:post_t st aL)
(preR:st.hprop) (#aR:Type) (postR:post_t st aR)
(next_preR:st.hprop) (next_postR:post_t st aR)
(state next_state:st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` st.invariant state) state)
(ensures
st.interp ((preL `st.star` next_preR) `st.star` st.invariant next_state) next_state)
= commute_star_right (st.invariant state) preL preR;
apply_interp_ext
(st.invariant state `st.star` (preL `st.star` preR))
(st.invariant state `st.star` (preR `st.star` preL))
state;
commute_star_right (st.invariant next_state) next_preR preL;
apply_interp_ext
(st.invariant next_state `st.star` (next_preR `st.star` preL))
(st.invariant next_state `st.star` (preL `st.star` next_preR))
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)
(f:m st a pre post{Ret? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Ret p x = f in
Step f
let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post {Act? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Act f = f in
let x = f () in
Step (Ret post x)
module M = FStar.MST
let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f /\ Ret? (Bind?.f f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f)
= M.MSTATE?.reflect (fun m0 ->
match f with
| Bind (Ret p x) g -> Step (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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MST",
"short_module": "M"
},
{
"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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f: CSL.Semantics.m st a pre post {Bind? f /\ Ret? (Bind?.f f)}
-> CSL.Semantics.Mst (CSL.Semantics.step_result st a) | CSL.Semantics.Mst | [] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.post_t",
"CSL.Semantics.m",
"Prims.l_and",
"Prims.b2t",
"CSL.Semantics.uu___is_Bind",
"CSL.Semantics.uu___is_Ret",
"CSL.Semantics.__proj__Bind__item__a",
"CSL.Semantics.__proj__Bind__item__pre",
"CSL.Semantics.__proj__Bind__item__post_a",
"CSL.Semantics.__proj__Bind__item__f",
"FStar.Pervasives.Native.tuple2",
"FStar.NMST.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"CSL.Semantics.step_result",
"CSL.Semantics.step_bind_ret_aux",
"CSL.Semantics.step_req",
"CSL.Semantics.step_ens"
] | [] | false | true | false | false | false | let step_bind_ret
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Bind? f /\ Ret? (Bind?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f) =
| NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux f, n) | false |
Hacl.HPKE.P256_CP32_SHA256.fsti | Hacl.HPKE.P256_CP32_SHA256.cs | val cs:S.ciphersuite | val cs:S.ciphersuite | let cs:S.ciphersuite = (DH.DH_P256, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256) | {
"file_name": "code/hpke/Hacl.HPKE.P256_CP32_SHA256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 10,
"start_col": 0,
"start_line": 10
} | module Hacl.HPKE.P256_CP32_SHA256
open Hacl.Impl.HPKE
module S = Spec.Agile.HPKE
module DH = Spec.Agile.DH
module AEAD = Spec.Agile.AEAD
module Hash = Spec.Agile.Hash | {
"checked_file": "/",
"dependencies": [
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"Spec.Agile.DH.fst.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"Hacl.Impl.HPKE.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.P256_CP32_SHA256.fsti"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Agile.HPKE.ciphersuite | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.Mktuple4",
"Spec.Agile.DH.algorithm",
"Spec.Agile.HPKE.hash_algorithm",
"Spec.Agile.HPKE.aead",
"Spec.Hash.Definitions.hash_alg",
"Spec.Agile.DH.DH_P256",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Agile.HPKE.Seal",
"Spec.Agile.AEAD.CHACHA20_POLY1305"
] | [] | false | false | false | true | false | let cs:S.ciphersuite =
| (DH.DH_P256, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256) | false |
CSL.Semantics.fst | CSL.Semantics.par_weaker_lpre_and_stronger_lpost_r | val par_weaker_lpre_and_stronger_lpost_r
(#st: st)
(preL: st.hprop)
(#aL: Type)
(postL: post_t st aL)
(preR: st.hprop)
(#aR: Type)
(postR: post_t st aR)
(next_preR: st.hprop)
(next_postR: post_t st aR)
(state next_state: st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` (st.invariant state)) state)
(ensures st.interp ((preL `st.star` next_preR) `st.star` (st.invariant next_state)) next_state
) | val par_weaker_lpre_and_stronger_lpost_r
(#st: st)
(preL: st.hprop)
(#aL: Type)
(postL: post_t st aL)
(preR: st.hprop)
(#aR: Type)
(postR: post_t st aR)
(next_preR: st.hprop)
(next_postR: post_t st aR)
(state next_state: st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` (st.invariant state)) state)
(ensures st.interp ((preL `st.star` next_preR) `st.star` (st.invariant next_state)) next_state
) | let par_weaker_lpre_and_stronger_lpost_r (#st:st)
(preL:st.hprop) (#aL:Type) (postL:post_t st aL)
(preR:st.hprop) (#aR:Type) (postR:post_t st aR)
(next_preR:st.hprop) (next_postR:post_t st aR)
(state next_state:st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` st.invariant state) state)
(ensures
st.interp ((preL `st.star` next_preR) `st.star` st.invariant next_state) next_state)
= commute_star_right (st.invariant state) preL preR;
apply_interp_ext
(st.invariant state `st.star` (preL `st.star` preR))
(st.invariant state `st.star` (preR `st.star` preL))
state;
commute_star_right (st.invariant next_state) next_preR preL;
apply_interp_ext
(st.invariant next_state `st.star` (next_preR `st.star` preL))
(st.invariant next_state `st.star` (preL `st.star` next_preR))
next_state | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 470,
"start_col": 0,
"start_line": 450
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#pop-options
#push-options "--z3rlimit 40 --warn_error -271"
let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
()
let preserves_frame_star_left (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()]
= commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext
(st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
()
#pop-options
/// 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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
preL: Mkst0?.hprop st ->
postL: CSL.Semantics.post_t st aL ->
preR: Mkst0?.hprop st ->
postR: CSL.Semantics.post_t st aR ->
next_preR: Mkst0?.hprop st ->
next_postR: CSL.Semantics.post_t st aR ->
state: Mkst0?.mem st ->
next_state: Mkst0?.mem st
-> FStar.Pervasives.Lemma
(requires
CSL.Semantics.preserves_frame preR next_preR state next_state /\
Mkst0?.interp st
(Mkst0?.star st (Mkst0?.star st preL preR) (Mkst0?.invariant st state))
state)
(ensures
Mkst0?.interp st
(Mkst0?.star st (Mkst0?.star st preL next_preR) (Mkst0?.invariant st next_state))
next_state) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.post_t",
"CSL.Semantics.__proj__Mkst0__item__mem",
"CSL.Semantics.apply_interp_ext",
"CSL.Semantics.__proj__Mkst0__item__star",
"CSL.Semantics.__proj__Mkst0__item__invariant",
"Prims.unit",
"CSL.Semantics.commute_star_right",
"Prims.l_and",
"CSL.Semantics.preserves_frame",
"CSL.Semantics.__proj__Mkst0__item__interp",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let par_weaker_lpre_and_stronger_lpost_r
(#st: st)
(preL: st.hprop)
(#aL: Type)
(postL: post_t st aL)
(preR: st.hprop)
(#aR: Type)
(postR: post_t st aR)
(next_preR: st.hprop)
(next_postR: post_t st aR)
(state next_state: st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` (st.invariant state)) state)
(ensures st.interp ((preL `st.star` next_preR) `st.star` (st.invariant next_state)) next_state
) =
| commute_star_right (st.invariant state) preL preR;
apply_interp_ext ((st.invariant state) `st.star` (preL `st.star` preR))
((st.invariant state) `st.star` (preR `st.star` preL))
state;
commute_star_right (st.invariant next_state) next_preR preL;
apply_interp_ext ((st.invariant next_state) `st.star` (next_preR `st.star` preL))
((st.invariant next_state) `st.star` (preL `st.star` next_preR))
next_state | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_code_ShiftKey1_128 | val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code | val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code | let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ()))))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 44,
"start_col": 0,
"start_line": 38
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | va_dummy: Prims.unit -> Vale.X64.Decls.va_code | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Vale.X64.Decls.va_Block",
"Vale.X64.Decls.va_CCons",
"Vale.X64.InsVector.va_code_Mov128",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.AES.X64.GF128_Mul.va_code_ShiftLeft128_1",
"Vale.AES.X64.PolyOps.va_code_PolyAnd",
"Vale.X64.InsVector.va_code_Pcmpeqd",
"Vale.X64.InsVector.va_code_Pshufd",
"Vale.AES.X64.PolyOps.va_code_VPolyAdd",
"Vale.X64.Decls.va_op_opr128_xmm",
"Vale.X64.Decls.va_CNil",
"Vale.X64.Decls.va_code"
] | [] | false | false | false | true | false | let va_code_ShiftKey1_128 () =
| (va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3))
(va_CCons (va_code_ShiftLeft128_1 ())
(va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255)
(va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1)
(va_op_xmm_xmm 1)
(va_op_opr128_xmm 3))
(va_CNil ()))))))))) | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_code_ShiftKey1_gf128_power | val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code | val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code | let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ())))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 178,
"start_col": 0,
"start_line": 173
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | va_dummy: Prims.unit -> Vale.X64.Decls.va_code | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Vale.X64.Decls.va_Block",
"Vale.X64.Decls.va_CCons",
"Vale.X64.InsVector.va_code_ZeroXmm",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.X64.InsVector.va_code_PinsrdImm",
"Vale.X64.Decls.va_op_reg_opr64_reg64",
"Vale.X64.Machine_s.rR12",
"Vale.AES.X64.GF128_Init.va_code_ShiftKey1_128",
"Vale.X64.Decls.va_CNil",
"Vale.X64.Decls.va_code"
] | [] | false | false | false | true | false | let va_code_ShiftKey1_gf128_power () =
| (va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4))
(va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 5))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)
)
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 5)
2147483648
3
(va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_ShiftKey1_128 ()) (va_CNil ())))))))) | false |
CSL.Semantics.fst | CSL.Semantics.preserves_frame_stronger_post | val preserves_frame_stronger_post
(#st: st)
(#a: Type)
(pre: st.hprop)
(post post_s: post_t st a)
(x: a)
(m1 m2: st.mem)
: Lemma (requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2) | val preserves_frame_stronger_post
(#st: st)
(#a: Type)
(pre: st.hprop)
(post post_s: post_t st a)
(x: a)
(m1 m2: st.mem)
: Lemma (requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2) | let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
() | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 393,
"start_col": 0,
"start_line": 359
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= () | {
"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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: CSL.Semantics.post_t st a ->
post_s: CSL.Semantics.post_t st a ->
x: a ->
m1: Mkst0?.mem st ->
m2: Mkst0?.mem st
-> FStar.Pervasives.Lemma
(requires
CSL.Semantics.preserves_frame pre (post_s x) m1 m2 /\
CSL.Semantics.stronger_post post post_s)
(ensures CSL.Semantics.preserves_frame pre (post x) m1 m2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.post_t",
"CSL.Semantics.__proj__Mkst0__item__mem",
"Prims.unit",
"CSL.Semantics.__proj__Mkst0__item__interp",
"CSL.Semantics.__proj__Mkst0__item__star",
"CSL.Semantics.__proj__Mkst0__item__invariant",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"Prims._assert",
"FStar.Calc.calc_finish",
"CSL.Semantics.__proj__Mkst0__item__equals",
"FStar.Preorder.relation",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"CSL.Semantics.apply_assoc",
"Prims.l_and",
"CSL.Semantics.preserves_frame",
"CSL.Semantics.stronger_post"
] | [] | false | false | true | false | false | let preserves_frame_stronger_post
(#st: st)
(#a: Type)
(pre: st.hprop)
(post post_s: post_t st a)
(x: a)
(m1 m2: st.mem)
: Lemma (requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2) =
| let aux (frame: st.hprop)
: Lemma (requires st.interp ((st.invariant m1) `st.star` (pre `st.star` frame)) m1)
(ensures st.interp ((st.invariant m2) `st.star` ((post x) `st.star` frame)) m2)
[SMTPat ()] =
assert (st.interp ((st.invariant m2) `st.star` ((post_s x) `st.star` frame)) m2);
calc (st.equals) {
(st.invariant m2) `st.star` ((post_s x) `st.star` frame);
(st.equals) { () }
((st.invariant m2) `st.star` (post_s x)) `st.star` frame;
(st.equals) { () }
((post_s x) `st.star` (st.invariant m2)) `st.star` frame;
(st.equals) { () }
(post_s x) `st.star` ((st.invariant m2) `st.star` frame);
};
assert (st.interp ((post_s x) `st.star` ((st.invariant m2) `st.star` frame)) m2);
assert (st.interp ((post x) `st.star` ((st.invariant m2) `st.star` frame)) m2);
calc (st.equals) {
(post x) `st.star` ((st.invariant m2) `st.star` frame);
(st.equals) { () }
((post x) `st.star` (st.invariant m2)) `st.star` frame;
(st.equals) { () }
((st.invariant m2) `st.star` (post x)) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
(st.invariant m2) `st.star` ((post x) `st.star` frame);
};
assert (st.interp ((st.invariant m2) `st.star` ((post x) `st.star` frame)) m2)
in
() | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_wp_ShiftKey1_128 | val va_wp_ShiftKey1_128 (f: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 | val va_wp_ShiftKey1_128 (f: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 | let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 85,
"end_line": 146,
"start_col": 0,
"start_line": 133
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: Vale.Math.Poly2_s.poly ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Math.Poly2_s.poly",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.avx_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Prims.eq2",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Vale.X64.Decls.va_get_xmm",
"Vale.Math.Poly2_s.monomial",
"Vale.Math.Poly2_s.reverse",
"Vale.Math.Poly2_s.shift",
"Vale.Math.Poly2_s.add",
"Prims.op_Minus",
"Prims.l_Forall",
"Vale.X64.Flags.t",
"Vale.X64.Decls.quad32",
"Prims.l_imp",
"Vale.AES.GF128.shift_key_1",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_flags"
] | [] | false | false | false | true | true | let va_wp_ShiftKey1_128 (f: poly) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
| (va_get_ok va_s0 /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
let h1:Vale.Math.Poly2_s.poly = Vale.Math.Poly2_s.shift h 1 in
let offset:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) == Vale.Math.Poly2_s.monomial 127 /\
offset ==
Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift (Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial
128)
f)
(- 1))
127) /\
(forall (va_x_efl: Vale.X64.Flags.t) (va_x_xmm1: quad32) (va_x_xmm2: quad32) (va_x_xmm3: quad32).
let va_sM =
va_upd_xmm 3
va_x_xmm3
(va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags va_x_efl va_s0)))
in
va_get_ok va_sM /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
let h1:Vale.Math.Poly2_s.poly = Vale.Math.Poly2_s.shift h 1 in
let offset:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==>
va_k va_sM (()))) | false |
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.ecdsa_verify_avoid_finv1 | val ecdsa_verify_avoid_finv1:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
(_X /% _Z % q = r) ==> ((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X))) | val ecdsa_verify_avoid_finv1:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
(_X /% _Z % q = r) ==> ((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X))) | let ecdsa_verify_avoid_finv1 p r =
let _X, _Y, _Z = p in
let x = _X /% _Z in
assert_norm (prime < 2 * q);
assert_norm (q < prime);
if x < q then begin
Math.Lemmas.small_mod x q;
assert ((x % q = r) == (x = r));
assert (r < prime /\ _X < prime /\ _Z < prime /\ _Z <> 0);
lemma_div_mod_eq_mul_mod _X _Z r;
assert ((x % q = r) == (r *% _Z = _X));
() end
else begin
Math.Lemmas.lemma_mod_sub x q (-1);
Math.Lemmas.small_mod (x - q) q;
assert (x % q == x - q);
assert ((x % q = r) == (x = r + q));
if r + q < prime then begin
lemma_div_mod_eq_mul_mod _X _Z (r + q);
assert ((x % q = r) == (r + q < prime && (r + q) *% _Z = _X)) end
else () end | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 113,
"start_col": 0,
"start_line": 92
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime)
let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz
let lemma_proj_aff_id p =
let (px, py) = p in
let (pX, pY, pZ) = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let (rx, ry) = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY)
let aff_point_at_inf_lemma p = ()
let aff_point_add_assoc_lemma p q s = admit()
let aff_point_add_comm_lemma p q = admit()
let aff_point_negate_lemma p =
let p_neg = aff_point_negate p in
let px, py = p in
let qx, qy = p_neg in
assert (qx = px /\ qy = (-py) % prime);
assert (aff_point_add p_neg p == aff_point_at_inf)
let to_aff_point_at_infinity_lemma () =
let px, py = to_aff_point point_at_inf in
assert (px == zero /% zero /\ py == one /% zero);
assert (px == zero *% M.pow_mod #prime zero (prime - 2));
M.lemma_pow_mod #prime zero (prime - 2);
assert (px == zero *% (M.pow zero (prime - 2) % prime));
M.lemma_pow_zero (prime - 2);
assert (px == zero /\ py == zero)
let to_aff_point_add_lemma p q = admit()
let to_aff_point_double_lemma p = admit()
let to_aff_point_negate_lemma p =
let px, py, pz = p in
let qx, qy = to_aff_point (point_negate p) in
assert (qx == px /% pz /\ qy == (- py) % prime /% pz);
let ax, ay = aff_point_negate (to_aff_point p) in
assert (ax == px /% pz /\ ay == (- py /% pz) % prime);
let pz_inv = M.pow_mod #prime pz (prime - 2) in
calc (==) { // (-py) % prime /% pz;
((- py) % prime * pz_inv) % prime;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (- py) pz_inv prime }
(- py * pz_inv) % prime;
(==) { Math.Lemmas.neg_mul_left py pz_inv }
(- (py * pz_inv)) % prime;
(==) { Math.Lemmas.lemma_mod_sub_distr 0 (py * pz_inv) prime }
(- (py * pz_inv) % prime) % prime; // (- py /% pz) % prime;
}
//----------------------------------
val lemma_div_mod_eq_mul_mod (a b c:felem) : Lemma
(requires b <> 0)
(ensures (a *% finv b = c) == (a = c *% b))
let lemma_div_mod_eq_mul_mod a b c =
prime_lemma ();
M.lemma_div_mod_eq_mul_mod #prime a b c
val ecdsa_verify_avoid_finv1:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
(_X /% _Z % q = r) ==> ((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X))) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Spec.K256.PointOps.proj_point{Prims.op_Negation (Spec.K256.PointOps.is_proj_point_at_inf p)} ->
r: Prims.nat{0 < r /\ r < Spec.K256.PointOps.q}
-> FStar.Pervasives.Lemma
(ensures
(let _ = p in
(let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ _X _ _Z = _ in
_X /% _Z % Spec.K256.PointOps.q = r ==>
r *% _Z = _X ||
r + Spec.K256.PointOps.q < Spec.K256.PointOps.prime &&
(r + Spec.K256.PointOps.q) *% _Z = _X)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.proj_point",
"Prims.b2t",
"Prims.op_Negation",
"Spec.K256.PointOps.is_proj_point_at_inf",
"Prims.nat",
"Prims.l_and",
"Prims.op_LessThan",
"Spec.K256.PointOps.q",
"Spec.K256.PointOps.felem",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Spec.K256.PointOps.op_Star_Percent",
"Spec.K256.Lemmas.lemma_div_mod_eq_mul_mod",
"Spec.K256.PointOps.prime",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Math.Lemmas.small_mod",
"Prims.op_Addition",
"Prims.op_AmpAmp",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.lemma_mod_sub",
"Prims.op_Minus",
"FStar.Pervasives.assert_norm",
"FStar.Mul.op_Star",
"Spec.K256.PointOps.op_Slash_Percent"
] | [] | false | false | true | false | false | let ecdsa_verify_avoid_finv1 p r =
| let _X, _Y, _Z = p in
let x = _X /% _Z in
assert_norm (prime < 2 * q);
assert_norm (q < prime);
if x < q
then
(Math.Lemmas.small_mod x q;
assert ((x % q = r) == (x = r));
assert (r < prime /\ _X < prime /\ _Z < prime /\ _Z <> 0);
lemma_div_mod_eq_mul_mod _X _Z r;
assert ((x % q = r) == (r *% _Z = _X));
())
else
(Math.Lemmas.lemma_mod_sub x q (- 1);
Math.Lemmas.small_mod (x - q) q;
assert (x % q == x - q);
assert ((x % q = r) == (x = r + q));
if r + q < prime
then
(lemma_div_mod_eq_mul_mod _X _Z (r + q);
assert ((x % q = r) == (r + q < prime && (r + q) *% _Z = _X)))) | false |
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.lemma_div_mod_eq_mul_mod | val lemma_div_mod_eq_mul_mod (a b c:felem) : Lemma
(requires b <> 0)
(ensures (a *% finv b = c) == (a = c *% b)) | val lemma_div_mod_eq_mul_mod (a b c:felem) : Lemma
(requires b <> 0)
(ensures (a *% finv b = c) == (a = c *% b)) | let lemma_div_mod_eq_mul_mod a b c =
prime_lemma ();
M.lemma_div_mod_eq_mul_mod #prime a b c | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 84,
"start_col": 0,
"start_line": 82
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime)
let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz
let lemma_proj_aff_id p =
let (px, py) = p in
let (pX, pY, pZ) = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let (rx, ry) = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY)
let aff_point_at_inf_lemma p = ()
let aff_point_add_assoc_lemma p q s = admit()
let aff_point_add_comm_lemma p q = admit()
let aff_point_negate_lemma p =
let p_neg = aff_point_negate p in
let px, py = p in
let qx, qy = p_neg in
assert (qx = px /\ qy = (-py) % prime);
assert (aff_point_add p_neg p == aff_point_at_inf)
let to_aff_point_at_infinity_lemma () =
let px, py = to_aff_point point_at_inf in
assert (px == zero /% zero /\ py == one /% zero);
assert (px == zero *% M.pow_mod #prime zero (prime - 2));
M.lemma_pow_mod #prime zero (prime - 2);
assert (px == zero *% (M.pow zero (prime - 2) % prime));
M.lemma_pow_zero (prime - 2);
assert (px == zero /\ py == zero)
let to_aff_point_add_lemma p q = admit()
let to_aff_point_double_lemma p = admit()
let to_aff_point_negate_lemma p =
let px, py, pz = p in
let qx, qy = to_aff_point (point_negate p) in
assert (qx == px /% pz /\ qy == (- py) % prime /% pz);
let ax, ay = aff_point_negate (to_aff_point p) in
assert (ax == px /% pz /\ ay == (- py /% pz) % prime);
let pz_inv = M.pow_mod #prime pz (prime - 2) in
calc (==) { // (-py) % prime /% pz;
((- py) % prime * pz_inv) % prime;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (- py) pz_inv prime }
(- py * pz_inv) % prime;
(==) { Math.Lemmas.neg_mul_left py pz_inv }
(- (py * pz_inv)) % prime;
(==) { Math.Lemmas.lemma_mod_sub_distr 0 (py * pz_inv) prime }
(- (py * pz_inv) % prime) % prime; // (- py /% pz) % prime;
}
//----------------------------------
val lemma_div_mod_eq_mul_mod (a b c:felem) : Lemma
(requires b <> 0)
(ensures (a *% finv b = c) == (a = c *% b)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.K256.PointOps.felem -> b: Spec.K256.PointOps.felem -> c: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma (requires b <> 0)
(ensures a *% Spec.K256.PointOps.finv b = c == (a = c *% b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Lib.NatMod.lemma_div_mod_eq_mul_mod",
"Spec.K256.PointOps.prime",
"Prims.unit",
"Spec.K256.Lemmas.prime_lemma"
] | [] | true | false | true | false | false | let lemma_div_mod_eq_mul_mod a b c =
| prime_lemma ();
M.lemma_div_mod_eq_mul_mod #prime a b c | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_codegen_success_ShiftKey1_128 | val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool | val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool | let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ())))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 55,
"start_col": 0,
"start_line": 48
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | va_dummy: Prims.unit -> Vale.X64.Decls.va_pbool | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Vale.X64.Decls.va_pbool_and",
"Vale.X64.InsVector.va_codegen_success_Mov128",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.AES.X64.GF128_Mul.va_codegen_success_ShiftLeft128_1",
"Vale.AES.X64.PolyOps.va_codegen_success_PolyAnd",
"Vale.X64.InsVector.va_codegen_success_Pcmpeqd",
"Vale.X64.InsVector.va_codegen_success_Pshufd",
"Vale.AES.X64.PolyOps.va_codegen_success_VPolyAdd",
"Vale.X64.Decls.va_op_opr128_xmm",
"Vale.X64.Decls.va_ttrue",
"Vale.X64.Decls.va_pbool"
] | [] | false | false | false | true | false | let va_codegen_success_ShiftKey1_128 () =
| (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3))
(va_pbool_and (va_codegen_success_ShiftLeft128_1 ())
(va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255)
(va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1)
(va_op_xmm_xmm 1)
(va_op_opr128_xmm 3))
(va_ttrue ())))))))) | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_codegen_success_ShiftKey1_gf128_power | val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool | val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool | let va_codegen_success_ShiftKey1_gf128_power () =
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_PinsrdImm
(va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ()))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 188,
"start_col": 0,
"start_line": 182
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ()))))))))
val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | va_dummy: Prims.unit -> Vale.X64.Decls.va_pbool | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Vale.X64.Decls.va_pbool_and",
"Vale.X64.InsVector.va_codegen_success_ZeroXmm",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.X64.InsVector.va_codegen_success_PinsrdImm",
"Vale.X64.Decls.va_op_reg_opr64_reg64",
"Vale.X64.Machine_s.rR12",
"Vale.AES.X64.GF128_Init.va_codegen_success_ShiftKey1_128",
"Vale.X64.Decls.va_ttrue",
"Vale.X64.Decls.va_pbool"
] | [] | false | false | false | true | false | let va_codegen_success_ShiftKey1_gf128_power () =
| (va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 5))
(va_pbool_and (va_codegen_success_PinsrdImm (va_op_xmm_xmm 4)
3254779904
3
(va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_PinsrdImm (va_op_xmm_xmm 4)
1
0
(va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_PinsrdImm (va_op_xmm_xmm 5)
2147483648
3
(va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ()))))))) | false |
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.to_aff_point_at_infinity_lemma | val to_aff_point_at_infinity_lemma: unit ->
Lemma (to_aff_point point_at_inf == aff_point_at_inf) | val to_aff_point_at_infinity_lemma: unit ->
Lemma (to_aff_point point_at_inf == aff_point_at_inf) | let to_aff_point_at_infinity_lemma () =
let px, py = to_aff_point point_at_inf in
assert (px == zero /% zero /\ py == one /% zero);
assert (px == zero *% M.pow_mod #prime zero (prime - 2));
M.lemma_pow_mod #prime zero (prime - 2);
assert (px == zero *% (M.pow zero (prime - 2) % prime));
M.lemma_pow_zero (prime - 2);
assert (px == zero /\ py == zero) | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 52,
"start_col": 0,
"start_line": 45
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime)
let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz
let lemma_proj_aff_id p =
let (px, py) = p in
let (pX, pY, pZ) = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let (rx, ry) = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY)
let aff_point_at_inf_lemma p = ()
let aff_point_add_assoc_lemma p q s = admit()
let aff_point_add_comm_lemma p q = admit()
let aff_point_negate_lemma p =
let p_neg = aff_point_negate p in
let px, py = p in
let qx, qy = p_neg in
assert (qx = px /\ qy = (-py) % prime);
assert (aff_point_add p_neg p == aff_point_at_inf) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
Spec.K256.PointOps.to_aff_point Spec.K256.PointOps.point_at_inf ==
Spec.K256.PointOps.aff_point_at_inf) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"Spec.K256.PointOps.felem",
"Prims._assert",
"Prims.l_and",
"Prims.eq2",
"Spec.K256.PointOps.zero",
"Lib.NatMod.lemma_pow_zero",
"Prims.op_Subtraction",
"Spec.K256.PointOps.prime",
"Spec.K256.PointOps.op_Star_Percent",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Lib.NatMod.lemma_pow_mod",
"Lib.NatMod.pow_mod",
"Spec.K256.PointOps.op_Slash_Percent",
"Spec.K256.PointOps.one",
"Spec.K256.PointOps.aff_point",
"Spec.K256.PointOps.to_aff_point",
"Spec.K256.PointOps.point_at_inf"
] | [] | false | false | true | false | false | let to_aff_point_at_infinity_lemma () =
| let px, py = to_aff_point point_at_inf in
assert (px == zero /% zero /\ py == one /% zero);
assert (px == zero *% M.pow_mod #prime zero (prime - 2));
M.lemma_pow_mod #prime zero (prime - 2);
assert (px == zero *% (M.pow zero (prime - 2) % prime));
M.lemma_pow_zero (prime - 2);
assert (px == zero /\ py == zero) | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_code_Gf128_powers | val va_code_Gf128_powers : va_dummy:unit -> Tot va_code | val va_code_Gf128_powers : va_dummy:unit -> Tot va_code | let va_code_Gf128_powers () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_CCons (va_code_Load128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRcx) 32 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128
(va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons (va_code_ShiftKey1_gf128_power ()) (va_CCons
(va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_CNil
())))))))))))))))))))))))))))))))))))))))))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 331,
"start_col": 0,
"start_line": 292
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ()))))))))
val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_gf128_power () =
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_PinsrdImm
(va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ())))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_gf128_power (va_mods:va_mods_t) (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 119 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 4)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 120 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 5)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 121 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 122 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 123 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (fun
(va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 124 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_high_bit ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 125 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_low_shift_1 ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 127 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_128 gf128_modulus_low_terms) (fun (va_s:va_state) _ -> let
(va_arg16:Prims.nat) = n in let (va_arg15:Vale.Math.Poly2_s.poly) = h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 128 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_gf128_power va_arg15 va_arg16) (va_QEmpty (()))))))))))))
val va_lemma_ShiftKey1_gf128_power : va_b0:va_code -> va_s0:va_state -> h:poly -> n:nat
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_gf128_power ()) va_s0 /\ va_get_ok va_s0 /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) /\
va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0))))))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_gf128_power va_b0 va_s0 h n =
let (va_mods:va_mods_t) = [va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_gf128_power va_mods h n in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_gf128_power ()) va_qc va_s0
(fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 105 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in label va_range1
"***** POSTCONDITION NOT MET AT line 117 column 45 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_gf128_power (h:poly) (n:nat) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n) /\
(forall (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) . let va_sM = va_upd_xmm 5 va_x_xmm5
(va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl va_s0)))))) in va_get_ok va_sM /\ (let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) ==>
va_k va_sM (())))
val va_wpProof_ShiftKey1_gf128_power : h:poly -> n:nat -> va_s0:va_state -> va_k:(va_state -> unit
-> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_gf128_power h n va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm
5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags])
va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_gf128_power h n va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_gf128_power (va_code_ShiftKey1_gf128_power ()) va_s0 h n
in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0)))))))));
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_gf128_power (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(va_QProc (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags]) (va_wp_ShiftKey1_gf128_power h n)
(va_wpProof_ShiftKey1_gf128_power h n))
//--
//-- Gf128_powers
val va_code_Gf128_powers : va_dummy:unit -> Tot va_code | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | va_dummy: Prims.unit -> Vale.X64.Decls.va_code | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Vale.X64.Decls.va_Block",
"Vale.X64.Decls.va_CCons",
"Vale.X64.InsVector.va_code_Mov128",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.X64.InsBasic.va_code_Mov64",
"Vale.X64.Decls.va_op_dst_opr64_reg64",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_op_opr64_reg64",
"Vale.X64.Machine_s.rR12",
"Vale.X64.InsVector.va_code_Load128_buffer",
"Vale.X64.Decls.va_op_heaplet_mem_heaplet",
"Vale.X64.Decls.va_op_reg_opr64_reg64",
"Vale.X64.Machine_s.rRcx",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.AES.X64.GF128_Init.va_code_ShiftKey1_gf128_power",
"Vale.X64.InsVector.va_code_Store128_buffer",
"Vale.AES.X64.GF128_Mul.va_code_Gf128MulRev128",
"Vale.X64.Decls.va_CNil",
"Vale.X64.Decls.va_code"
] | [] | false | false | false | true | false | let va_code_Gf128_powers () =
| (va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6))
(va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12))
(va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx)
32
Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1))
(va_CCons (va_code_ShiftKey1_gf128_power ())
(va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1)
0
Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6))
(va_CCons (va_code_Gf128MulRev128 ())
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6)
(va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 3)
(va_op_xmm_xmm 1))
(va_CCons (va_code_ShiftKey1_gf128_power ())
(va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet
1)
(va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1)
16
Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm
2)
(va_op_xmm_xmm 6))
(va_CCons (va_code_Load128_buffer (va_op_heaplet_mem_heaplet
1)
(va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx)
32
Secret)
(va_CCons (va_code_Gf128MulRev128
())
(va_CCons (va_code_Mov128 (va_op_xmm_xmm
6)
(va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128
(va_op_xmm_xmm 3
)
(va_op_xmm_xmm 1
))
(va_CCons (va_code_ShiftKey1_gf128_power
())
(va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet
1)
(va_op_reg_opr64_reg64
rRcx
)
(va_op_xmm_xmm
1)
48
Secret)
(va_CCons (va_code_Mov128
(va_op_xmm_xmm
2
)
(va_op_xmm_xmm
6
))
(va_CCons
(va_code_Load128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_xmm_xmm
1
)
(
va_op_reg_opr64_reg64
rRcx
)
32
Secret
)
(va_CCons
(
va_code_Gf128MulRev128
()
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
1
)
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
3
)
(
va_op_xmm_xmm
1
)
)
(
va_CCons
(
va_code_ShiftKey1_gf128_power
()
)
(
va_CCons
(
va_code_Store128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_reg_opr64_reg64
rRcx
)
(
va_op_xmm_xmm
1
)
64
Secret
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
2
)
(
va_op_xmm_xmm
6
)
)
(
va_CCons
(
va_code_Load128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_xmm_xmm
1
)
(
va_op_reg_opr64_reg64
rRcx
)
32
Secret
)
(
va_CCons
(
va_code_Gf128MulRev128
()
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
1
)
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
3
)
(
va_op_xmm_xmm
1
)
)
(
va_CCons
(
va_code_ShiftKey1_gf128_power
()
)
(
va_CCons
(
va_code_Store128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_reg_opr64_reg64
rRcx
)
(
va_op_xmm_xmm
1
)
96
Secret
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
2
)
(
va_op_xmm_xmm
6
)
)
(
va_CCons
(
va_code_Load128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_xmm_xmm
1
)
(
va_op_reg_opr64_reg64
rRcx
)
32
Secret
)
(
va_CCons
(
va_code_Gf128MulRev128
()
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
1
)
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
3
)
(
va_op_xmm_xmm
1
)
)
(
va_CCons
(
va_code_ShiftKey1_gf128_power
()
)
(
va_CCons
(
va_code_Store128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_reg_opr64_reg64
rRcx
)
(
va_op_xmm_xmm
1
)
112
Secret
)
(
va_CCons
(
va_code_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
0
)
)
(
va_CCons
(
va_code_Mov64
(
va_op_dst_opr64_reg64
rR12
)
(
va_op_opr64_reg64
rRax
)
)
(
va_CNil
()
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))))
))))))))))) | false |
Spec.K256.Lemmas.fst | Spec.K256.Lemmas.ecdsa_verify_avoid_finv2 | val ecdsa_verify_avoid_finv2:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X)) ==> (_X /% _Z % q = r)) | val ecdsa_verify_avoid_finv2:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X)) ==> (_X /% _Z % q = r)) | let ecdsa_verify_avoid_finv2 p r =
let _X, _Y, _Z = p in
let x = _X /% _Z in
assert_norm (prime < 2 * q);
assert_norm (q < prime);
if r *% _Z = _X then begin
lemma_div_mod_eq_mul_mod _X _Z r;
Math.Lemmas.small_mod x q;
assert (r = x % q) end
else begin
if r + q < prime && (r + q) *% _Z = _X then begin
lemma_div_mod_eq_mul_mod _X _Z (r + q);
assert (r + q = x);
Math.Lemmas.small_mod (x - q) q;
Math.Lemmas.lemma_mod_sub x q (-1);
assert (r = x % q) end
else () end | {
"file_name": "specs/lemmas/Spec.K256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 138,
"start_col": 0,
"start_line": 121
} | module Spec.K256.Lemmas
open FStar.Mul
open Spec.K256.PointOps
module Euclid = FStar.Math.Euclid
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
assume val prime_lemma: unit -> Lemma (Euclid.is_prime prime)
let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz
let lemma_proj_aff_id p =
let (px, py) = p in
let (pX, pY, pZ) = to_proj_point p in
assert (pX = px /\ pY = pY /\ pZ = one);
let (rx, ry) = to_aff_point (pX, pY, pZ) in
assert (rx = (pX /% pZ) /\ ry = (pY /% pZ));
M.lemma_div_mod_prime_one #prime pX;
M.lemma_div_mod_prime_one #prime pY;
assert (rx = pX /\ ry = pY)
let aff_point_at_inf_lemma p = ()
let aff_point_add_assoc_lemma p q s = admit()
let aff_point_add_comm_lemma p q = admit()
let aff_point_negate_lemma p =
let p_neg = aff_point_negate p in
let px, py = p in
let qx, qy = p_neg in
assert (qx = px /\ qy = (-py) % prime);
assert (aff_point_add p_neg p == aff_point_at_inf)
let to_aff_point_at_infinity_lemma () =
let px, py = to_aff_point point_at_inf in
assert (px == zero /% zero /\ py == one /% zero);
assert (px == zero *% M.pow_mod #prime zero (prime - 2));
M.lemma_pow_mod #prime zero (prime - 2);
assert (px == zero *% (M.pow zero (prime - 2) % prime));
M.lemma_pow_zero (prime - 2);
assert (px == zero /\ py == zero)
let to_aff_point_add_lemma p q = admit()
let to_aff_point_double_lemma p = admit()
let to_aff_point_negate_lemma p =
let px, py, pz = p in
let qx, qy = to_aff_point (point_negate p) in
assert (qx == px /% pz /\ qy == (- py) % prime /% pz);
let ax, ay = aff_point_negate (to_aff_point p) in
assert (ax == px /% pz /\ ay == (- py /% pz) % prime);
let pz_inv = M.pow_mod #prime pz (prime - 2) in
calc (==) { // (-py) % prime /% pz;
((- py) % prime * pz_inv) % prime;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (- py) pz_inv prime }
(- py * pz_inv) % prime;
(==) { Math.Lemmas.neg_mul_left py pz_inv }
(- (py * pz_inv)) % prime;
(==) { Math.Lemmas.lemma_mod_sub_distr 0 (py * pz_inv) prime }
(- (py * pz_inv) % prime) % prime; // (- py /% pz) % prime;
}
//----------------------------------
val lemma_div_mod_eq_mul_mod (a b c:felem) : Lemma
(requires b <> 0)
(ensures (a *% finv b = c) == (a = c *% b))
let lemma_div_mod_eq_mul_mod a b c =
prime_lemma ();
M.lemma_div_mod_eq_mul_mod #prime a b c
val ecdsa_verify_avoid_finv1:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
(_X /% _Z % q = r) ==> ((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X)))
let ecdsa_verify_avoid_finv1 p r =
let _X, _Y, _Z = p in
let x = _X /% _Z in
assert_norm (prime < 2 * q);
assert_norm (q < prime);
if x < q then begin
Math.Lemmas.small_mod x q;
assert ((x % q = r) == (x = r));
assert (r < prime /\ _X < prime /\ _Z < prime /\ _Z <> 0);
lemma_div_mod_eq_mul_mod _X _Z r;
assert ((x % q = r) == (r *% _Z = _X));
() end
else begin
Math.Lemmas.lemma_mod_sub x q (-1);
Math.Lemmas.small_mod (x - q) q;
assert (x % q == x - q);
assert ((x % q = r) == (x = r + q));
if r + q < prime then begin
lemma_div_mod_eq_mul_mod _X _Z (r + q);
assert ((x % q = r) == (r + q < prime && (r + q) *% _Z = _X)) end
else () end
val ecdsa_verify_avoid_finv2:
p:proj_point{not (is_proj_point_at_inf p)} -> r:nat{0 < r /\ r < q} ->
Lemma (let _X, _Y, _Z = p in
((r *% _Z = _X) || (r + q < prime && (r + q) *% _Z = _X)) ==> (_X /% _Z % q = r)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.K256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "LM"
},
{
"abbrev": false,
"full_module": "Spec.K256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Spec.K256.PointOps.proj_point{Prims.op_Negation (Spec.K256.PointOps.is_proj_point_at_inf p)} ->
r: Prims.nat{0 < r /\ r < Spec.K256.PointOps.q}
-> FStar.Pervasives.Lemma
(ensures
(let _ = p in
(let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ _X _ _Z = _ in
r *% _Z = _X ||
r + Spec.K256.PointOps.q < Spec.K256.PointOps.prime &&
(r + Spec.K256.PointOps.q) *% _Z = _X ==>
_X /% _Z % Spec.K256.PointOps.q = r)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.proj_point",
"Prims.b2t",
"Prims.op_Negation",
"Spec.K256.PointOps.is_proj_point_at_inf",
"Prims.nat",
"Prims.l_and",
"Prims.op_LessThan",
"Spec.K256.PointOps.q",
"Spec.K256.PointOps.felem",
"Prims.op_Equality",
"Spec.K256.PointOps.op_Star_Percent",
"Prims._assert",
"Prims.int",
"Prims.op_Modulus",
"Prims.unit",
"FStar.Math.Lemmas.small_mod",
"Spec.K256.Lemmas.lemma_div_mod_eq_mul_mod",
"Prims.bool",
"Prims.op_AmpAmp",
"Prims.op_Addition",
"Spec.K256.PointOps.prime",
"FStar.Math.Lemmas.lemma_mod_sub",
"Prims.op_Minus",
"Prims.op_Subtraction",
"FStar.Pervasives.assert_norm",
"FStar.Mul.op_Star",
"Spec.K256.PointOps.op_Slash_Percent"
] | [] | false | false | true | false | false | let ecdsa_verify_avoid_finv2 p r =
| let _X, _Y, _Z = p in
let x = _X /% _Z in
assert_norm (prime < 2 * q);
assert_norm (q < prime);
if r *% _Z = _X
then
(lemma_div_mod_eq_mul_mod _X _Z r;
Math.Lemmas.small_mod x q;
assert (r = x % q))
else
if r + q < prime && (r + q) *% _Z = _X
then
(lemma_div_mod_eq_mul_mod _X _Z (r + q);
assert (r + q = x);
Math.Lemmas.small_mod (x - q) q;
Math.Lemmas.lemma_mod_sub x q (- 1);
assert (r = x % q)) | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_wp_Gf128_powers | val va_wp_Gf128_powers
(h: poly)
(hkeys_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Gf128_powers
(h: poly)
(hkeys_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Gf128_powers (h:poly) (hkeys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRcx va_s0) hkeys_b
8 (va_get_mem_layout va_s0) Secret /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0)) == h /\ (forall
(va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_efl:Vale.X64.Flags.t) (va_x_rax:nat64)
(va_x_r12:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32)
(va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) . let va_sM = va_upd_xmm 6 va_x_xmm6
(va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rRax
va_x_rax (va_upd_flags va_x_efl (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem
va_s0))))))))))) in va_get_ok va_sM /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64
rR12 va_sM == va_get_reg64 rR12 va_s0 /\ Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer
#Vale.X64.Memory.vuint128 hkeys_b) (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 1 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 2 /\ Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 3 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 4 /\ Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 5 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 6 ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 611,
"start_col": 0,
"start_line": 583
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ()))))))))
val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_gf128_power () =
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_PinsrdImm
(va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ())))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_gf128_power (va_mods:va_mods_t) (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 119 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 4)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 120 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 5)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 121 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 122 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 123 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (fun
(va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 124 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_high_bit ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 125 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_low_shift_1 ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 127 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_128 gf128_modulus_low_terms) (fun (va_s:va_state) _ -> let
(va_arg16:Prims.nat) = n in let (va_arg15:Vale.Math.Poly2_s.poly) = h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 128 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_gf128_power va_arg15 va_arg16) (va_QEmpty (()))))))))))))
val va_lemma_ShiftKey1_gf128_power : va_b0:va_code -> va_s0:va_state -> h:poly -> n:nat
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_gf128_power ()) va_s0 /\ va_get_ok va_s0 /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) /\
va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0))))))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_gf128_power va_b0 va_s0 h n =
let (va_mods:va_mods_t) = [va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_gf128_power va_mods h n in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_gf128_power ()) va_qc va_s0
(fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 105 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in label va_range1
"***** POSTCONDITION NOT MET AT line 117 column 45 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_gf128_power (h:poly) (n:nat) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n) /\
(forall (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) . let va_sM = va_upd_xmm 5 va_x_xmm5
(va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl va_s0)))))) in va_get_ok va_sM /\ (let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) ==>
va_k va_sM (())))
val va_wpProof_ShiftKey1_gf128_power : h:poly -> n:nat -> va_s0:va_state -> va_k:(va_state -> unit
-> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_gf128_power h n va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm
5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags])
va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_gf128_power h n va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_gf128_power (va_code_ShiftKey1_gf128_power ()) va_s0 h n
in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0)))))))));
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_gf128_power (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(va_QProc (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags]) (va_wp_ShiftKey1_gf128_power h n)
(va_wpProof_ShiftKey1_gf128_power h n))
//--
//-- Gf128_powers
val va_code_Gf128_powers : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Gf128_powers () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_CCons (va_code_Load128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRcx) 32 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128
(va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons (va_code_ShiftKey1_gf128_power ()) (va_CCons
(va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_CNil
()))))))))))))))))))))))))))))))))))))))))))))))
val va_codegen_success_Gf128_powers : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Gf128_powers () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm
1)) (va_pbool_and (va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and
(va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1)
(va_op_xmm_xmm 6)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm
6)) (va_pbool_and (va_codegen_success_Gf128MulRev128 ()) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_ttrue
())))))))))))))))))))))))))))))))))))))))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Gf128_powers (va_mods:va_mods_t) (h:poly) (hkeys_b:buffer128) : (va_quickCode unit
(va_code_Gf128_powers ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 158 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 159 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 161 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (fun (va_s:va_state) _ -> let (va_arg57:Vale.Math.Poly2_s.poly) = h
in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 162 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_1 va_arg57) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 163 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 164 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 165 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 166 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret hkeys_b 0) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 168 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 169 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 170 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg56:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 171 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg56 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 172 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 173 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 174 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 175 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 16 Secret hkeys_b 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 177 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 178 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 179 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg55:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 180 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg55 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 181 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 182 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 183 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 184 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 48 Secret hkeys_b 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 186 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 187 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 188 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg54:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 189 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg54 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 190 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 191 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 192 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 193 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 64 Secret hkeys_b 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 195 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 196 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 197 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg53:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 198 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg53 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 199 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 200 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 201 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 5) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 202 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 96 Secret hkeys_b 6) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 204 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 205 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 206 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg52:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 207 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg52 5) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 208 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 209 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 210 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 6) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 211 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 112 Secret hkeys_b 7) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 213 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 214 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_QEmpty
(())))))))))))))))))))))))))))))))))))))))))))))))))))))
val va_lemma_Gf128_powers : va_b0:va_code -> va_s0:va_state -> h:poly -> hkeys_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gf128_powers ()) va_s0 /\ va_get_ok va_s0 /\
(pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRcx va_s0) hkeys_b 8 (va_get_mem_layout va_s0)
Secret /\ Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 2
(va_get_mem_heaplet 1 va_s0)) == h))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0
/\ Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 hkeys_b)
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 1 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 2 /\ Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 3 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 4 /\ Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 5 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 6 /\ va_state_eq va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rRax va_sM
(va_update_flags va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM
va_s0)))))))))))))))
[@"opaque_to_smt"]
let va_lemma_Gf128_powers va_b0 va_s0 h hkeys_b =
let (va_mods:va_mods_t) = [va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_ok; va_Mod_mem] in
let va_qc = va_qcode_Gf128_powers va_mods h hkeys_b in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Gf128_powers ()) va_qc va_s0 (fun va_s0
va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 131 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 145 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 146 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 147 column 61 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 hkeys_b)
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 148 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 1) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 149 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 2) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 151 column 84 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 152 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 3) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 153 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 4) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 154 column 84 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 155 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 5) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 156 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 6)) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_ok; va_Mod_mem]) va_sM va_s0;
(va_sM, va_fM) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Math.Poly2_s.poly ->
hkeys_b: Vale.X64.Memory.buffer128 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Math.Poly2_s.poly",
"Vale.X64.Memory.buffer128",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.pclmulqdq_enabled",
"Vale.X64.CPU_Features_s.avx_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Vale.X64.Decls.validDstAddrs128",
"Vale.X64.Decls.va_get_mem_heaplet",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.eq2",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Vale.X64.Decls.buffer128_read",
"Prims.l_Forall",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Flags.t",
"Vale.X64.Memory.nat64",
"Vale.X64.Decls.quad32",
"Prims.l_imp",
"Vale.X64.Decls.va_get_xmm",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Decls.loc_buffer",
"Vale.X64.Memory.vuint128",
"Vale.AES.GHash.gf128_power",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_Gf128_powers
(h: poly)
(hkeys_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0)
(va_get_reg64 rRcx va_s0)
hkeys_b
8
(va_get_mem_layout va_s0)
Secret /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b
2
(va_get_mem_heaplet 1 va_s0)) ==
h /\
(forall (va_x_mem: vale_heap) (va_x_heap1: vale_heap) (va_x_efl: Vale.X64.Flags.t)
(va_x_rax: nat64) (va_x_r12: nat64) (va_x_xmm0: quad32) (va_x_xmm1: quad32)
(va_x_xmm2: quad32) (va_x_xmm3: quad32) (va_x_xmm4: quad32) (va_x_xmm5: quad32)
(va_x_xmm6: quad32).
let va_sM =
va_upd_xmm 6
va_x_xmm6
(va_upd_xmm 5
va_x_xmm5
(va_upd_xmm 4
va_x_xmm4
(va_upd_xmm 3
va_x_xmm3
(va_upd_xmm 2
va_x_xmm2
(va_upd_xmm 1
va_x_xmm1
(va_upd_xmm 0
va_x_xmm0
(va_upd_reg64 rR12
va_x_r12
(va_upd_reg64 rRax
va_x_rax
(va_upd_flags va_x_efl
(va_upd_mem_heaplet 1
va_x_heap1
(va_upd_mem va_x_mem va_s0)))))))))))
in
va_get_ok va_sM /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\
va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 hkeys_b)
(va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b
0
(va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 1 /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b
1
(va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 2 /\
Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b
3
(va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 3 /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b
4
(va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 4 /\
Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b
6
(va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 5 /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b
7
(va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 6 ==>
va_k va_sM (()))) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.returnc | val returnc (a: Type) (x: a) : repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1) | val returnc (a: Type) (x: a) : repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1) | let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 46,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> x: a
-> HoareSTPolyBind.repr a (fun _ -> Prims.l_True) (fun h0 r h1 -> r == x /\ h0 == h1) | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"HoareSTPolyBind.repr",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2"
] | [] | false | false | false | false | false | let returnc (a: Type) (x: a) : repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1) =
| fun _ -> x | false |
CSL.Semantics.fst | CSL.Semantics.step_par_ret_aux | val step_par_ret_aux
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f) | val step_par_ret_aux
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f) | let step_par_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f)
= M.MSTATE?.reflect (fun m0 ->
let Par (Ret pL xL) (Ret pR xR) = f in
Step (Ret (fun (xL, xR) -> pL xL `st.star` pR xR) (xL, xR)), m0) | {
"file_name": "share/steel/examples/steel/CSL.Semantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 68,
"end_line": 578,
"start_col": 0,
"start_line": 573
} | (*
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 CSL.Semantics
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
*
* Using the semantics, we derive a CSL in a partial correctness setting.
*)
#push-options "--fuel 0 --ifuel 2 --z3rlimit 20 --print_implicits --print_universes \
--using_facts_from 'Prims FStar.Pervasives FStar.Preorder MST NMST CSL.Semantics'"
(**** Begin state defn ****)
/// We start by defining some basic notions for a commutative monoid.
///
/// We could reuse FStar.Algebra.CommMonoid, but this style with
/// quanitifers 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
noeq
type st0 = {
mem:Type u#2;
evolves:P.preorder mem;
hprop:Type u#2;
invariant: mem -> hprop;
interp: hprop -> mem -> prop;
emp:hprop;
star: hprop -> hprop -> hprop;
equals: hprop -> hprop -> prop;
}
////////////////////////////////////////////////////////////////////////////////
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 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
let st = s:st0 { st_laws s }
(**** End state defn ****)
(**** Begin expects, provides 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
(**** End expects, provides defns ****)
effect Mst (a:Type) (#st:st) (req:st.mem -> Type0) (ens:st.mem -> a -> st.mem -> Type0) =
NMSTATE a st.mem st.evolves req ens
(**** Begin interface of actions ****)
/// Actions are essentially state transformers that preserve frames
let preserves_frame (#st:st) (pre post:st.hprop) (m0 m1:st.mem) =
forall (frame:st.hprop).
st.interp ((pre `st.star` frame) `st.star` (st.invariant m0)) m0 ==>
st.interp ((post `st.star` frame) `st.star` (st.invariant m1)) m1
let action_t
(#st:st)
(#a:Type)
(pre:st.hprop)
(post:post_t st a)
= unit ->
Mst a
(requires fun m0 -> st.interp (pre `st.star` st.invariant m0) m0)
(ensures fun m0 x m1 ->
st.interp ((post x) `st.star` st.invariant m1) m1 /\
preserves_frame pre (post x) m0 m1)
(**** End interface of actions ****)
(**** Begin definition of the computation AST ****)
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)
(wpre:st.hprop) (wpost:post_t st a)
= weaker_pre wpre pre /\ stronger_post wpost post
noeq
type m (st:st) :
a:Type u#a ->
pre:st.hprop ->
post:post_t st a -> Type
=
| Ret:
#a:Type u#a ->
post:post_t st a ->
x:a ->
m st a (post x) post
| Bind:
#a:Type u#a ->
#pre:st.hprop ->
#post_a:post_t st a ->
#b:Type u#a ->
#post_b:post_t st b ->
f:m st a pre post_a ->
g:(x:a -> Dv (m st b (post_a x) post_b)) ->
m st b pre post_b
| Act:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
f:action_t #st #a pre post ->
m st a pre post
| Frame:
#a:Type ->
#pre:st.hprop ->
#post:post_t st a ->
f:m st a pre post ->
frame:st.hprop ->
m st a (pre `st.star` frame) (fun x -> post x `st.star` frame)
| Par:
#aL:Type u#a ->
#preL:st.hprop ->
#postL:post_t st aL ->
mL:m st aL preL postL ->
#aR:Type u#a ->
#preR:st.hprop ->
#postR:post_t st aR ->
mR:m st aR preR postR ->
m st (aL & aR) (preL `st.star` preR) (fun (xL, xR) -> postL xL `st.star` postR xR)
| Weaken:
#a:Type u#a ->
#pre:st.hprop ->
#post:post_t st a ->
wpre:st.hprop ->
wpost:post_t st a ->
_:squash (weakening_ok pre post wpre wpost) ->
m st a pre post ->
m st a wpre wpost
(**** 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 ->
m st a next_pre next_post ->
step_result st a
(**** Type of the single-step interpreter ****)
/// Interpreter is setup as an NMST function from computation trees to computation trees
///
/// As the computation evolves, the post becomes stronger
unfold
let step_req (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a) (f:m st a pre post)
: st.mem -> Type0
= fun m0 -> st.interp (pre `st.star` st.invariant m0) m0
unfold
let step_ens (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post)
: st.mem -> step_result st a -> st.mem -> Type0
= fun m0 r m1 ->
let Step #_ #_ #next_pre #next_post _ = r in
st.interp (next_pre `st.star` st.invariant m1) m1 /\
stronger_post post next_post /\
preserves_frame pre next_pre 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 ->
f:m st a pre post ->
Mst (step_result st a) (step_req f) (step_ens 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_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));
}
/// 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)
= ()
/// Lemmas about preserves_frame
let preserves_frame_trans (#st:st) (hp1 hp2 hp3:st.hprop) (m1 m2 m3:st.mem)
: Lemma
(requires preserves_frame hp1 hp2 m1 m2 /\ preserves_frame hp2 hp3 m2 m3)
(ensures preserves_frame hp1 hp3 m1 m3)
= ()
#push-options "--warn_error -271"
let preserves_frame_stronger_post (#st:st) (#a:Type)
(pre:st.hprop) (post post_s:post_t st a) (x:a)
(m1 m2:st.mem)
: Lemma
(requires preserves_frame pre (post_s x) m1 m2 /\ stronger_post post post_s)
(ensures preserves_frame pre (post x) m1 m2)
= let aux (frame:st.hprop)
: Lemma
(requires st.interp (st.invariant m1 `st.star` (pre `st.star` frame)) m1)
(ensures st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
[SMTPat ()]
= assert (st.interp (st.invariant m2 `st.star` (post_s x `st.star` frame)) m2);
calc (st.equals) {
st.invariant m2 `st.star` (post_s x `st.star` frame);
(st.equals) { }
(st.invariant m2 `st.star` post_s x) `st.star` frame;
(st.equals) { }
(post_s x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
post_s x `st.star` (st.invariant m2 `st.star` frame);
};
assert (st.interp (post_s x `st.star` (st.invariant m2 `st.star` frame)) m2);
assert (st.interp (post x `st.star` (st.invariant m2 `st.star` frame)) m2);
calc (st.equals) {
post x `st.star` (st.invariant m2 `st.star` frame);
(st.equals) { }
(post x `st.star` st.invariant m2) `st.star` frame;
(st.equals) { }
(st.invariant m2 `st.star` post x) `st.star` frame;
(st.equals) { apply_assoc (st.invariant m2) (post x) frame }
st.invariant m2 `st.star` (post x `st.star` frame);
};
assert (st.interp (st.invariant m2 `st.star` (post x `st.star` frame)) m2)
in
()
#pop-options
#push-options "--z3rlimit 40 --warn_error -271"
let preserves_frame_star (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (pre `st.star` frame) (post `st.star` frame) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame')) m1)
[SMTPat ()]
= assoc_star_right (st.invariant m0) pre frame frame';
apply_interp_ext
(st.invariant m0 `st.star` ((pre `st.star` frame) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
assoc_star_right (st.invariant m1) post frame frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((post `st.star` frame) `st.star` frame'))
m1
in
()
let preserves_frame_star_left (#st:st) (pre post:st.hprop) (m0 m1:st.mem) (frame:st.hprop)
: Lemma
(requires preserves_frame pre post m0 m1)
(ensures preserves_frame (frame `st.star` pre) (frame `st.star` post) m0 m1)
= let aux (frame':st.hprop)
: Lemma
(requires
st.interp (st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame')) m0)
(ensures
st.interp (st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame')) m1)
[SMTPat ()]
= commute_assoc_star_right (st.invariant m0) frame pre frame';
apply_interp_ext
(st.invariant m0 `st.star` ((frame `st.star` pre) `st.star` frame'))
(st.invariant m0 `st.star` (pre `st.star` (frame `st.star` frame')))
m0;
commute_assoc_star_right (st.invariant m1) frame post frame';
apply_interp_ext
(st.invariant m1 `st.star` (post `st.star` (frame `st.star` frame')))
(st.invariant m1 `st.star` ((frame `st.star` post) `st.star` frame'))
m1
in
()
#pop-options
/// Lemmas for proving that in the par rules preconditions get weaker
/// and postconditions get stronger
let par_weaker_lpre_and_stronger_lpost_r (#st:st)
(preL:st.hprop) (#aL:Type) (postL:post_t st aL)
(preR:st.hprop) (#aR:Type) (postR:post_t st aR)
(next_preR:st.hprop) (next_postR:post_t st aR)
(state next_state:st.mem)
: Lemma
(requires
preserves_frame preR next_preR state next_state /\
st.interp ((preL `st.star` preR) `st.star` st.invariant state) state)
(ensures
st.interp ((preL `st.star` next_preR) `st.star` st.invariant next_state) next_state)
= commute_star_right (st.invariant state) preL preR;
apply_interp_ext
(st.invariant state `st.star` (preL `st.star` preR))
(st.invariant state `st.star` (preR `st.star` preL))
state;
commute_star_right (st.invariant next_state) next_preR preL;
apply_interp_ext
(st.invariant next_state `st.star` (next_preR `st.star` preL))
(st.invariant next_state `st.star` (preL `st.star` next_preR))
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)
(f:m st a pre post{Ret? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Ret p x = f in
Step f
let step_act (#st:st) (#a:Type u#a) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post {Act? f})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Act f = f in
let x = f () in
Step (Ret post x)
module M = FStar.MST
let step_bind_ret_aux (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f /\ Ret? (Bind?.f f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f)
= M.MSTATE?.reflect (fun m0 ->
match f with
| Bind (Ret p x) g -> Step (g x), m0)
let step_bind_ret (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f /\ Ret? (Bind?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f)
= NMSTATE?.reflect (fun (_, n) -> step_bind_ret_aux f, n)
let step_bind (#st:st) (#a:Type) (#pre:st.hprop) (#post:post_t st a)
(f:m st a pre post{Bind? f})
(step:step_t)
: Mst (step_result st a) (step_req f) (step_ens f)
= match f with
| Bind (Ret _ _) _ -> step_bind_ret f
| Bind #_ #_ #_ #_ #_ #post_b f g ->
let Step #_ #_ #next_pre #next_post f = step f in
Step #_ #_ #next_pre #post_b
(Bind f (fun x -> Weaken (next_post x) _ () (g x)))
let step_frame_ret (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a)
(f:m st a pre p{Frame? f /\ Ret? (Frame?.f f)})
: Mst (step_result st a) (step_req f) (step_ens f)
= let Frame (Ret p x) frame = f in
Step (Ret (fun x -> p x `st.star` frame) x)
let step_frame (#st:st) (#a:Type) (#pre:st.hprop) (#p:post_t st a)
(f:m st a pre p{Frame? f})
(step:step_t)
: Mst (step_result st a) (step_req f) (step_ens f)
= match f with
| Frame (Ret _ _) _ -> step_frame_ret f
| Frame #_ #_ #f_pre #_ f frame ->
let m0 = get () in
let Step #_ #_ #next_fpre #next_fpost f = step f in
let m1 = get () in
preserves_frame_star f_pre next_fpre m0 m1 frame;
Step (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.NMST.fst.checked",
"FStar.MST.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "CSL.Semantics.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MST",
"short_module": "M"
},
{
"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": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CSL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f: CSL.Semantics.m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)}
-> FStar.MST.MSTATE (CSL.Semantics.step_result st a) | FStar.MST.MSTATE | [] | [] | [
"CSL.Semantics.st",
"CSL.Semantics.__proj__Mkst0__item__hprop",
"CSL.Semantics.post_t",
"CSL.Semantics.m",
"Prims.l_and",
"Prims.b2t",
"CSL.Semantics.uu___is_Par",
"CSL.Semantics.uu___is_Ret",
"CSL.Semantics.__proj__Par__item__aL",
"CSL.Semantics.__proj__Par__item__preL",
"CSL.Semantics.__proj__Par__item__postL",
"CSL.Semantics.__proj__Par__item__mL",
"CSL.Semantics.__proj__Par__item__aR",
"CSL.Semantics.__proj__Par__item__preR",
"CSL.Semantics.__proj__Par__item__postR",
"CSL.Semantics.__proj__Par__item__mR",
"CSL.Semantics.__proj__Mkst0__item__mem",
"FStar.Pervasives.Native.Mktuple2",
"CSL.Semantics.step_result",
"CSL.Semantics.Step",
"FStar.Pervasives.Native.tuple2",
"CSL.Semantics.__proj__Mkst0__item__star",
"CSL.Semantics.Ret",
"CSL.Semantics.__proj__Mkst0__item__evolves",
"CSL.Semantics.step_req",
"CSL.Semantics.step_ens"
] | [] | false | true | false | false | false | let step_par_ret_aux
(#st: st)
(#a: Type)
(#pre: st.hprop)
(#post: post_t st a)
(f: m st a pre post {Par? f /\ Ret? (Par?.mL f) /\ Ret? (Par?.mR f)})
: M.MSTATE (step_result st a) st.mem st.evolves (step_req f) (step_ens f) =
| M.MSTATE?.reflect (fun m0 ->
let Par (Ret pL xL) (Ret pR xR) = f in
Step (Ret (fun (xL, xR) -> (pL xL) `st.star` (pR xR)) (xL, xR)), m0) | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_codegen_success_Gf128_powers | val va_codegen_success_Gf128_powers : va_dummy:unit -> Tot va_pbool | val va_codegen_success_Gf128_powers : va_dummy:unit -> Tot va_pbool | let va_codegen_success_Gf128_powers () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm
1)) (va_pbool_and (va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and
(va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1)
(va_op_xmm_xmm 6)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm
6)) (va_pbool_and (va_codegen_success_Gf128MulRev128 ()) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_ttrue
()))))))))))))))))))))))))))))))))))))))))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 380,
"start_col": 0,
"start_line": 335
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ()))))))))
val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_gf128_power () =
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_PinsrdImm
(va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ())))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_gf128_power (va_mods:va_mods_t) (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 119 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 4)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 120 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 5)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 121 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 122 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 123 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (fun
(va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 124 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_high_bit ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 125 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_low_shift_1 ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 127 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_128 gf128_modulus_low_terms) (fun (va_s:va_state) _ -> let
(va_arg16:Prims.nat) = n in let (va_arg15:Vale.Math.Poly2_s.poly) = h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 128 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_gf128_power va_arg15 va_arg16) (va_QEmpty (()))))))))))))
val va_lemma_ShiftKey1_gf128_power : va_b0:va_code -> va_s0:va_state -> h:poly -> n:nat
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_gf128_power ()) va_s0 /\ va_get_ok va_s0 /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) /\
va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0))))))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_gf128_power va_b0 va_s0 h n =
let (va_mods:va_mods_t) = [va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_gf128_power va_mods h n in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_gf128_power ()) va_qc va_s0
(fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 105 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in label va_range1
"***** POSTCONDITION NOT MET AT line 117 column 45 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_gf128_power (h:poly) (n:nat) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n) /\
(forall (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) . let va_sM = va_upd_xmm 5 va_x_xmm5
(va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl va_s0)))))) in va_get_ok va_sM /\ (let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) ==>
va_k va_sM (())))
val va_wpProof_ShiftKey1_gf128_power : h:poly -> n:nat -> va_s0:va_state -> va_k:(va_state -> unit
-> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_gf128_power h n va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm
5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags])
va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_gf128_power h n va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_gf128_power (va_code_ShiftKey1_gf128_power ()) va_s0 h n
in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0)))))))));
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_gf128_power (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(va_QProc (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags]) (va_wp_ShiftKey1_gf128_power h n)
(va_wpProof_ShiftKey1_gf128_power h n))
//--
//-- Gf128_powers
val va_code_Gf128_powers : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Gf128_powers () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_CCons (va_code_Load128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRcx) 32 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128
(va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons (va_code_ShiftKey1_gf128_power ()) (va_CCons
(va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_CNil
()))))))))))))))))))))))))))))))))))))))))))))))
val va_codegen_success_Gf128_powers : va_dummy:unit -> Tot va_pbool | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | va_dummy: Prims.unit -> Vale.X64.Decls.va_pbool | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Vale.X64.Decls.va_pbool_and",
"Vale.X64.InsVector.va_codegen_success_Mov128",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.X64.InsBasic.va_codegen_success_Mov64",
"Vale.X64.Decls.va_op_dst_opr64_reg64",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_op_opr64_reg64",
"Vale.X64.Machine_s.rR12",
"Vale.X64.InsVector.va_codegen_success_Load128_buffer",
"Vale.X64.Decls.va_op_heaplet_mem_heaplet",
"Vale.X64.Decls.va_op_reg_opr64_reg64",
"Vale.X64.Machine_s.rRcx",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.AES.X64.GF128_Init.va_codegen_success_ShiftKey1_gf128_power",
"Vale.X64.InsVector.va_codegen_success_Store128_buffer",
"Vale.AES.X64.GF128_Mul.va_codegen_success_Gf128MulRev128",
"Vale.X64.Decls.va_ttrue",
"Vale.X64.Decls.va_pbool"
] | [] | false | false | false | true | false | let va_codegen_success_Gf128_powers () =
| (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6))
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx)
32
Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1))
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1))
(va_pbool_and (va_codegen_success_ShiftKey1_gf128_power ())
(va_pbool_and (va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet
1)
(va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1)
0
Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1)
(va_op_xmm_xmm 6))
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2)
(va_op_xmm_xmm 6))
(va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6)
(va_op_xmm_xmm 1))
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 3
)
(va_op_xmm_xmm 1))
(va_pbool_and (va_codegen_success_ShiftKey1_gf128_power
())
(va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1)
16
Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm
2)
(va_op_xmm_xmm 6))
(va_pbool_and (va_codegen_success_Load128_buffer
(va_op_heaplet_mem_heaplet 1)
(va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx)
32
Secret)
(va_pbool_and (va_codegen_success_Gf128MulRev128
())
(va_pbool_and (va_codegen_success_Mov128
(va_op_xmm_xmm 6)
(va_op_xmm_xmm 1))
(va_pbool_and (va_codegen_success_Mov128
(va_op_xmm_xmm 3)
(va_op_xmm_xmm 1))
(va_pbool_and (va_codegen_success_ShiftKey1_gf128_power
())
(va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet
1)
(va_op_reg_opr64_reg64
rRcx)
(va_op_xmm_xmm
1)
48
Secret)
(va_pbool_and (va_codegen_success_Mov128
(va_op_xmm_xmm
2)
(va_op_xmm_xmm
6))
(va_pbool_and
(va_codegen_success_Load128_buffer
(va_op_heaplet_mem_heaplet
1
)
(va_op_xmm_xmm
1
)
(va_op_reg_opr64_reg64
rRcx
)
32
Secret
)
(va_pbool_and
(va_codegen_success_Gf128MulRev128
()
)
(va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
1
)
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
3
)
(
va_op_xmm_xmm
1
)
)
(
va_pbool_and
(
va_codegen_success_ShiftKey1_gf128_power
()
)
(
va_pbool_and
(
va_codegen_success_Store128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_reg_opr64_reg64
rRcx
)
(
va_op_xmm_xmm
1
)
64
Secret
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
2
)
(
va_op_xmm_xmm
6
)
)
(
va_pbool_and
(
va_codegen_success_Load128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_xmm_xmm
1
)
(
va_op_reg_opr64_reg64
rRcx
)
32
Secret
)
(
va_pbool_and
(
va_codegen_success_Gf128MulRev128
()
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
1
)
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
3
)
(
va_op_xmm_xmm
1
)
)
(
va_pbool_and
(
va_codegen_success_ShiftKey1_gf128_power
()
)
(
va_pbool_and
(
va_codegen_success_Store128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_reg_opr64_reg64
rRcx
)
(
va_op_xmm_xmm
1
)
96
Secret
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
2
)
(
va_op_xmm_xmm
6
)
)
(
va_pbool_and
(
va_codegen_success_Load128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_xmm_xmm
1
)
(
va_op_reg_opr64_reg64
rRcx
)
32
Secret
)
(
va_pbool_and
(
va_codegen_success_Gf128MulRev128
()
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
1
)
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
3
)
(
va_op_xmm_xmm
1
)
)
(
va_pbool_and
(
va_codegen_success_ShiftKey1_gf128_power
()
)
(
va_pbool_and
(
va_codegen_success_Store128_buffer
(
va_op_heaplet_mem_heaplet
1
)
(
va_op_reg_opr64_reg64
rRcx
)
(
va_op_xmm_xmm
1
)
112
Secret
)
(
va_pbool_and
(
va_codegen_success_Mov128
(
va_op_xmm_xmm
6
)
(
va_op_xmm_xmm
0
)
)
(
va_pbool_and
(
va_codegen_success_Mov64
(
va_op_dst_opr64_reg64
rR12
)
(
va_op_opr64_reg64
rRax
)
)
(
va_ttrue
()
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))))
))))))))))) | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_wp_ShiftKey1_gf128_power | val va_wp_ShiftKey1_gf128_power
(h: poly)
(n: nat)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_ShiftKey1_gf128_power
(h: poly)
(n: nat)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_ShiftKey1_gf128_power (h:poly) (n:nat) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n) /\
(forall (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) . let va_sM = va_upd_xmm 5 va_x_xmm5
(va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl va_s0)))))) in va_get_ok va_sM /\ (let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) ==>
va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 258,
"start_col": 0,
"start_line": 248
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ()))))))))
val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_gf128_power () =
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_PinsrdImm
(va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ())))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_gf128_power (va_mods:va_mods_t) (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 119 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 4)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 120 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 5)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 121 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 122 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 123 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (fun
(va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 124 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_high_bit ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 125 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_low_shift_1 ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 127 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_128 gf128_modulus_low_terms) (fun (va_s:va_state) _ -> let
(va_arg16:Prims.nat) = n in let (va_arg15:Vale.Math.Poly2_s.poly) = h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 128 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_gf128_power va_arg15 va_arg16) (va_QEmpty (()))))))))))))
val va_lemma_ShiftKey1_gf128_power : va_b0:va_code -> va_s0:va_state -> h:poly -> n:nat
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_gf128_power ()) va_s0 /\ va_get_ok va_s0 /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) /\
va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0))))))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_gf128_power va_b0 va_s0 h n =
let (va_mods:va_mods_t) = [va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_gf128_power va_mods h n in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_gf128_power ()) va_qc va_s0
(fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 105 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in label va_range1
"***** POSTCONDITION NOT MET AT line 117 column 45 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok]) va_sM va_s0;
(va_sM, va_fM) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Math.Poly2_s.poly ->
n: Prims.nat ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Math.Poly2_s.poly",
"Prims.nat",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.avx_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Prims.eq2",
"Vale.AES.GHash.g_power",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Vale.X64.Decls.va_get_xmm",
"Prims.l_Forall",
"Vale.X64.Flags.t",
"Vale.X64.Memory.nat64",
"Vale.X64.Decls.quad32",
"Prims.l_imp",
"Vale.AES.GHash.gf128_power",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Decls.va_upd_flags"
] | [] | false | false | false | true | true | let va_wp_ShiftKey1_gf128_power
(h: poly)
(n: nat)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let hn:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n) /\
(forall (va_x_efl: Vale.X64.Flags.t)
(va_x_r12: nat64)
(va_x_xmm1: quad32)
(va_x_xmm2: quad32)
(va_x_xmm3: quad32)
(va_x_xmm4: quad32)
(va_x_xmm5: quad32).
let va_sM =
va_upd_xmm 5
va_x_xmm5
(va_upd_xmm 4
va_x_xmm4
(va_upd_xmm 3
va_x_xmm3
(va_upd_xmm 2
va_x_xmm2
(va_upd_xmm 1
va_x_xmm1
(va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl va_s0))))))
in
va_get_ok va_sM /\
(let hn:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) ==>
va_k va_sM (()))) | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_code_Keyhash_init | val va_code_Keyhash_init : win:bool -> alg:algorithm -> Tot va_code | val va_code_Keyhash_init : win:bool -> alg:algorithm -> Tot va_code | let va_code_Keyhash_init win alg =
(va_Block (va_CCons (va_code_CreateHeaplets ()) (va_CCons (va_code_InitPshufbMask (va_op_xmm_xmm
4) (va_op_reg_opr64_reg64 rR8)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 0)) (va_CCons (if win
then va_Block (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRdx) (va_op_xmm_xmm 0) 80 Secret) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rRcx)) (va_CNil ()))) else va_Block (va_CCons
(va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRsi)
(va_op_xmm_xmm 0) 80 Secret) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR8)
(va_op_opr64_reg64 rRdi)) (va_CNil ())))) (va_CCons (va_code_AESEncryptBlock alg) (va_CCons
(va_code_Pshufb (va_op_xmm_xmm 0) (va_op_xmm_xmm 4)) (va_CCons (if win then va_Block (va_CCons
(va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rRdx)) (va_CNil ())) else
va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rRsi))
(va_CNil ()))) (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 0) 32 Secret) (va_CCons (va_code_Gf128_powers ())
(va_CCons (va_Block (va_CNil ())) (va_CCons (va_code_DestroyHeaplets ()) (va_CNil
()))))))))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 662,
"start_col": 0,
"start_line": 647
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ()))))))))
val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_gf128_power () =
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_PinsrdImm
(va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ())))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_gf128_power (va_mods:va_mods_t) (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 119 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 4)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 120 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 5)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 121 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 122 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 123 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (fun
(va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 124 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_high_bit ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 125 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_low_shift_1 ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 127 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_128 gf128_modulus_low_terms) (fun (va_s:va_state) _ -> let
(va_arg16:Prims.nat) = n in let (va_arg15:Vale.Math.Poly2_s.poly) = h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 128 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_gf128_power va_arg15 va_arg16) (va_QEmpty (()))))))))))))
val va_lemma_ShiftKey1_gf128_power : va_b0:va_code -> va_s0:va_state -> h:poly -> n:nat
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_gf128_power ()) va_s0 /\ va_get_ok va_s0 /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) /\
va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0))))))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_gf128_power va_b0 va_s0 h n =
let (va_mods:va_mods_t) = [va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_gf128_power va_mods h n in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_gf128_power ()) va_qc va_s0
(fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 105 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in label va_range1
"***** POSTCONDITION NOT MET AT line 117 column 45 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_gf128_power (h:poly) (n:nat) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n) /\
(forall (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) . let va_sM = va_upd_xmm 5 va_x_xmm5
(va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl va_s0)))))) in va_get_ok va_sM /\ (let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) ==>
va_k va_sM (())))
val va_wpProof_ShiftKey1_gf128_power : h:poly -> n:nat -> va_s0:va_state -> va_k:(va_state -> unit
-> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_gf128_power h n va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm
5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags])
va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_gf128_power h n va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_gf128_power (va_code_ShiftKey1_gf128_power ()) va_s0 h n
in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0)))))))));
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_gf128_power (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(va_QProc (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags]) (va_wp_ShiftKey1_gf128_power h n)
(va_wpProof_ShiftKey1_gf128_power h n))
//--
//-- Gf128_powers
val va_code_Gf128_powers : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Gf128_powers () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_CCons (va_code_Load128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRcx) 32 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128
(va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons (va_code_ShiftKey1_gf128_power ()) (va_CCons
(va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_CNil
()))))))))))))))))))))))))))))))))))))))))))))))
val va_codegen_success_Gf128_powers : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Gf128_powers () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm
1)) (va_pbool_and (va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and
(va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1)
(va_op_xmm_xmm 6)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm
6)) (va_pbool_and (va_codegen_success_Gf128MulRev128 ()) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_ttrue
())))))))))))))))))))))))))))))))))))))))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Gf128_powers (va_mods:va_mods_t) (h:poly) (hkeys_b:buffer128) : (va_quickCode unit
(va_code_Gf128_powers ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 158 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 159 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 161 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (fun (va_s:va_state) _ -> let (va_arg57:Vale.Math.Poly2_s.poly) = h
in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 162 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_1 va_arg57) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 163 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 164 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 165 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 166 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret hkeys_b 0) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 168 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 169 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 170 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg56:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 171 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg56 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 172 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 173 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 174 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 175 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 16 Secret hkeys_b 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 177 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 178 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 179 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg55:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 180 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg55 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 181 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 182 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 183 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 184 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 48 Secret hkeys_b 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 186 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 187 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 188 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg54:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 189 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg54 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 190 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 191 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 192 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 193 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 64 Secret hkeys_b 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 195 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 196 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 197 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg53:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 198 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg53 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 199 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 200 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 201 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 5) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 202 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 96 Secret hkeys_b 6) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 204 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 205 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 206 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg52:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 207 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg52 5) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 208 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 209 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 210 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 6) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 211 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 112 Secret hkeys_b 7) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 213 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 214 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_QEmpty
(())))))))))))))))))))))))))))))))))))))))))))))))))))))
val va_lemma_Gf128_powers : va_b0:va_code -> va_s0:va_state -> h:poly -> hkeys_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gf128_powers ()) va_s0 /\ va_get_ok va_s0 /\
(pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRcx va_s0) hkeys_b 8 (va_get_mem_layout va_s0)
Secret /\ Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 2
(va_get_mem_heaplet 1 va_s0)) == h))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0
/\ Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 hkeys_b)
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 1 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 2 /\ Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 3 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 4 /\ Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 5 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 6 /\ va_state_eq va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rRax va_sM
(va_update_flags va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM
va_s0)))))))))))))))
[@"opaque_to_smt"]
let va_lemma_Gf128_powers va_b0 va_s0 h hkeys_b =
let (va_mods:va_mods_t) = [va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_ok; va_Mod_mem] in
let va_qc = va_qcode_Gf128_powers va_mods h hkeys_b in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Gf128_powers ()) va_qc va_s0 (fun va_s0
va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 131 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 145 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 146 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 147 column 61 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 hkeys_b)
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 148 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 1) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 149 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 2) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 151 column 84 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 152 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 3) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 153 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 4) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 154 column 84 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 155 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 5) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 156 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 6)) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_ok; va_Mod_mem]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_Gf128_powers (h:poly) (hkeys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRcx va_s0) hkeys_b
8 (va_get_mem_layout va_s0) Secret /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0)) == h /\ (forall
(va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_efl:Vale.X64.Flags.t) (va_x_rax:nat64)
(va_x_r12:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32)
(va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) . let va_sM = va_upd_xmm 6 va_x_xmm6
(va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rRax
va_x_rax (va_upd_flags va_x_efl (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem
va_s0))))))))))) in va_get_ok va_sM /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64
rR12 va_sM == va_get_reg64 rR12 va_s0 /\ Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer
#Vale.X64.Memory.vuint128 hkeys_b) (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 1 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 2 /\ Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 3 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 4 /\ Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 5 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 6 ==> va_k va_sM (())))
val va_wpProof_Gf128_powers : h:poly -> hkeys_b:buffer128 -> va_s0:va_state -> va_k:(va_state ->
unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gf128_powers h hkeys_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gf128_powers ()) ([va_Mod_xmm 6;
va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0;
va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0
va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_Gf128_powers h hkeys_b va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Gf128_powers (va_code_Gf128_powers ()) va_s0 h hkeys_b in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM
(va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM
(va_update_reg64 rR12 va_sM (va_update_reg64 rRax va_sM (va_update_flags va_sM
(va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))));
va_lemma_norm_mods ([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_mem]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_Gf128_powers (h:poly) (hkeys_b:buffer128) : (va_quickCode unit (va_code_Gf128_powers
())) =
(va_QProc (va_code_Gf128_powers ()) ([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_mem]) (va_wp_Gf128_powers h hkeys_b) (va_wpProof_Gf128_powers h
hkeys_b))
//--
//-- Keyhash_init | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | win: Prims.bool -> alg: Vale.AES.AES_common_s.algorithm -> Vale.X64.Decls.va_code | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.AES.AES_common_s.algorithm",
"Vale.X64.Decls.va_Block",
"Vale.X64.Decls.va_CCons",
"Vale.X64.InsMem.va_code_CreateHeaplets",
"Vale.X64.InsVector.va_code_InitPshufbMask",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.X64.Decls.va_op_reg_opr64_reg64",
"Vale.X64.Machine_s.rR8",
"Vale.X64.InsVector.va_code_ZeroXmm",
"Vale.X64.InsVector.va_code_Store128_buffer",
"Vale.X64.Decls.va_op_heaplet_mem_heaplet",
"Vale.X64.Machine_s.rRdx",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.InsBasic.va_code_Mov64",
"Vale.X64.Decls.va_op_dst_opr64_reg64",
"Vale.X64.Decls.va_op_opr64_reg64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Decls.va_CNil",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.Decls.va_code",
"Vale.AES.X64.AES.va_code_AESEncryptBlock",
"Vale.X64.InsVector.va_code_Pshufb",
"Vale.AES.X64.GF128_Init.va_code_Gf128_powers",
"Vale.X64.InsMem.va_code_DestroyHeaplets"
] | [] | false | false | false | true | false | let va_code_Keyhash_init win alg =
| (va_Block (va_CCons (va_code_CreateHeaplets ())
(va_CCons (va_code_InitPshufbMask (va_op_xmm_xmm 4) (va_op_reg_opr64_reg64 rR8))
(va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 0))
(va_CCons (if win
then
va_Block (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRdx)
(va_op_xmm_xmm 0)
80
Secret)
(va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR8)
(va_op_opr64_reg64 rRcx))
(va_CNil ())))
else
va_Block (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRsi)
(va_op_xmm_xmm 0)
80
Secret)
(va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR8)
(va_op_opr64_reg64 rRdi))
(va_CNil ()))))
(va_CCons (va_code_AESEncryptBlock alg)
(va_CCons (va_code_Pshufb (va_op_xmm_xmm 0) (va_op_xmm_xmm 4))
(va_CCons (if win
then
va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx)
(va_op_opr64_reg64 rRdx))
(va_CNil ()))
else
va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx)
(va_op_opr64_reg64 rRsi))
(va_CNil ())))
(va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 0)
32
Secret)
(va_CCons (va_code_Gf128_powers ())
(va_CCons (va_Block (va_CNil ()))
(va_CCons (va_code_DestroyHeaplets ()) (va_CNil ()))))))
))))))) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.get | val get: Prims.unit -> HoareST heap (fun _ -> True) (fun h0 h h1 -> h0 == h1 /\ h == h1) | val get: Prims.unit -> HoareST heap (fun _ -> True) (fun h0 h h1 -> h0 == h1 /\ h == h1) | let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 137,
"start_col": 0,
"start_line": 133
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> HoareSTPolyBind.HoareST FStar.Monotonic.Heap.heap | HoareSTPolyBind.HoareST | [] | [] | [
"Prims.unit",
"FStar.ST.get",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let get () : HoareST heap (fun _ -> True) (fun h0 h h1 -> h0 == h1 /\ h == h1) =
| HoareST?.reflect get | false |
HoareSTPolyBind.fst | HoareSTPolyBind.test | val test: Prims.unit -> HoareST int (fun _ -> True) (fun _ r _ -> r == 1) | val test: Prims.unit -> HoareST int (fun _ -> True) (fun _ r _ -> r == 1) | let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1)
= f 0 | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 200,
"start_col": 0,
"start_line": 199
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n
let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n
assume val f : x:int -> HoareST int (fun _ -> True) (fun _ r _ -> r == x + 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> HoareSTPolyBind.HoareST Prims.int | HoareSTPolyBind.HoareST | [] | [] | [
"Prims.unit",
"HoareSTPolyBind.f",
"Prims.int",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.eq2"
] | [] | false | true | false | false | false | let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1) =
| f 0 | false |
HoareSTPolyBind.fst | HoareSTPolyBind.test2 | val test2: Prims.unit -> HoareST int (fun _ -> True) (fun _ _ _ -> True) | val test2: Prims.unit -> HoareST int (fun _ -> True) (fun _ _ _ -> True) | let test2 () : HoareST int (fun _ -> True) (fun _ _ _ -> True)
= g 2 (f 0) | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 207,
"start_col": 0,
"start_line": 206
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n
let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n
assume val f : x:int -> HoareST int (fun _ -> True) (fun _ r _ -> r == x + 1)
let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1)
= f 0
open FStar.Monotonic.Pure
assume val g : int -> int -> PURE int (as_pure_wp (fun p -> forall x. p x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> HoareSTPolyBind.HoareST Prims.int | HoareSTPolyBind.HoareST | [] | [] | [
"Prims.unit",
"HoareSTPolyBind.g",
"Prims.int",
"HoareSTPolyBind.f",
"FStar.Monotonic.Heap.heap",
"Prims.l_True"
] | [] | false | true | false | false | false | let test2 () : HoareST int (fun _ -> True) (fun _ _ _ -> True) =
| g 2 (f 0) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.bind | val bind
(a b: Type)
(#pre_f: pre_t)
(#post_f: post_t a)
(#pre_g: (a -> pre_t))
(#post_g: (a -> post_t b))
(f: repr a pre_f post_f)
(g: (x: a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x: a) (h1: heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x: a) (h1: heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2) | val bind
(a b: Type)
(#pre_f: pre_t)
(#post_f: post_t a)
(#pre_g: (a -> pre_t))
(#post_g: (a -> post_t b))
(f: repr a pre_f post_f)
(g: (x: a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x: a) (h1: heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x: a) (h1: heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2) | let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x () | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 8,
"end_line": 59,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
b: Type ->
f: HoareSTPolyBind.repr a pre_f post_f ->
g: (x: a -> HoareSTPolyBind.repr b (pre_g x) (post_g x))
-> HoareSTPolyBind.repr b
(fun h0 ->
pre_f h0 /\ (forall (x: a) (h1: FStar.Monotonic.Heap.heap). post_f h0 x h1 ==> pre_g x h1)
)
(fun h0 y h2 ->
exists (x: a) (h1: FStar.Monotonic.Heap.heap).
pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2) | Prims.Tot | [
"total"
] | [] | [
"HoareSTPolyBind.pre_t",
"HoareSTPolyBind.post_t",
"HoareSTPolyBind.repr",
"Prims.unit",
"FStar.Monotonic.Heap.heap",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_Exists"
] | [] | false | false | false | false | false | let bind
(a b: Type)
(#pre_f: pre_t)
(#post_f: post_t a)
(#pre_g: (a -> pre_t))
(#post_g: (a -> post_t b))
(f: repr a pre_f post_f)
(g: (x: a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x: a) (h1: heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x: a) (h1: heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2) =
| fun _ ->
let x = f () in
g x () | false |
HoareSTPolyBind.fst | HoareSTPolyBind.test_dep_f | val test_dep_f: Prims.unit -> HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) | val test_dep_f: Prims.unit -> HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) | let test_dep_f () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
dep_f (pure_g ()) | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 229,
"start_col": 0,
"start_line": 228
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n
let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n
assume val f : x:int -> HoareST int (fun _ -> True) (fun _ r _ -> r == x + 1)
let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1)
= f 0
open FStar.Monotonic.Pure
assume val g : int -> int -> PURE int (as_pure_wp (fun p -> forall x. p x))
let test2 () : HoareST int (fun _ -> True) (fun _ _ _ -> True)
= g 2 (f 0)
(*
// * In the polymonadic bind (PURE, HoareST) |> HoareST, the return type of
// * g is not allowed to depend on x, the return value of f
// *
// * So then what happens when a function f whose return type depends on its argument
// * is applied to a PURE term
// * NOTE: PURE and not Tot, since Tot will just be substituted,
// * without even invoking the bind
// *
// * When typechecking f e, the comp type is roughly
// * bind C_e C_ret_f, where C_ret_f is the comp type of f (below the arrow binder)
// * This is where bind comes in
// *)
assume type t_int (x:int) : Type0
assume val dep_f (x:int) : HoareST (t_int x) (fun _ -> True) (fun _ _ _ -> True)
assume val pure_g (_:unit) : PURE int (as_pure_wp (fun p -> forall (x:int). x >= 2 ==> p x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> HoareSTPolyBind.HoareST (HoareSTPolyBind.t_int (HoareSTPolyBind.pure_g ())) | HoareSTPolyBind.HoareST | [] | [] | [
"Prims.unit",
"HoareSTPolyBind.dep_f",
"HoareSTPolyBind.pure_g",
"HoareSTPolyBind.t_int",
"FStar.Monotonic.Heap.heap",
"Prims.l_True"
] | [] | false | true | false | false | false | let test_dep_f () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
| dep_f (pure_g ()) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.test_dep_f2 | val test_dep_f2: Prims.unit -> HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) | val test_dep_f2: Prims.unit -> HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) | let test_dep_f2 () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
let x = pure_g () in
dep_f x | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 247,
"start_col": 0,
"start_line": 245
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n
let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n
assume val f : x:int -> HoareST int (fun _ -> True) (fun _ r _ -> r == x + 1)
let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1)
= f 0
open FStar.Monotonic.Pure
assume val g : int -> int -> PURE int (as_pure_wp (fun p -> forall x. p x))
let test2 () : HoareST int (fun _ -> True) (fun _ _ _ -> True)
= g 2 (f 0)
(*
// * In the polymonadic bind (PURE, HoareST) |> HoareST, the return type of
// * g is not allowed to depend on x, the return value of f
// *
// * So then what happens when a function f whose return type depends on its argument
// * is applied to a PURE term
// * NOTE: PURE and not Tot, since Tot will just be substituted,
// * without even invoking the bind
// *
// * When typechecking f e, the comp type is roughly
// * bind C_e C_ret_f, where C_ret_f is the comp type of f (below the arrow binder)
// * This is where bind comes in
// *)
assume type t_int (x:int) : Type0
assume val dep_f (x:int) : HoareST (t_int x) (fun _ -> True) (fun _ _ _ -> True)
assume val pure_g (_:unit) : PURE int (as_pure_wp (fun p -> forall (x:int). x >= 2 ==> p x))
let test_dep_f () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
dep_f (pure_g ())
(*
// * This works!
// *
// * The reason is that, before bind is called, the typechecker has already
// * substituted the pure term (pure_g ()) into the comp type of dep_f
// * (below the binder)
// *)
(*
// * But what happens when this is an explicit let binding?
// * as opposed to a function application
// *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> HoareSTPolyBind.HoareST (HoareSTPolyBind.t_int (HoareSTPolyBind.pure_g ())) | HoareSTPolyBind.HoareST | [] | [] | [
"Prims.unit",
"HoareSTPolyBind.dep_f",
"HoareSTPolyBind.t_int",
"Prims.int",
"HoareSTPolyBind.pure_g",
"FStar.Monotonic.Heap.heap",
"Prims.l_True"
] | [] | false | true | false | false | false | let test_dep_f2 () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
| let x = pure_g () in
dep_f x | false |
HoareSTPolyBind.fst | HoareSTPolyBind.recall | val recall (#a: Type) (#rel: P.preorder a) (r: mref a rel)
: HoareST unit (fun _ -> True) (fun h0 _ h1 -> h0 == h1 /\ h1 `Heap.contains` r) | val recall (#a: Type) (#rel: P.preorder a) (r: mref a rel)
: HoareST unit (fun _ -> True) (fun h0 _ h1 -> h0 == h1 /\ h1 `Heap.contains` r) | let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r) | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 105,
"start_col": 0,
"start_line": 99
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.ST.mref a rel -> HoareSTPolyBind.HoareST Prims.unit | HoareSTPolyBind.HoareST | [] | [] | [
"FStar.Preorder.preorder",
"FStar.ST.mref",
"Prims.unit",
"FStar.ST.recall",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.Heap.contains"
] | [] | false | true | false | false | false | let recall (#a: Type) (#rel: P.preorder a) (r: mref a rel)
: HoareST unit (fun _ -> True) (fun h0 _ h1 -> h0 == h1 /\ h1 `Heap.contains` r) =
| HoareST?.reflect (fun _ -> recall r) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.return | val return (#a: Type) (x: a) : HoareST a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1) | val return (#a: Type) (x: a) : HoareST a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1) | let return (#a:Type) (x:a)
: HoareST a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= HoareST?.reflect (returnc a x) | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 324,
"start_col": 0,
"start_line": 322
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n
let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n
assume val f : x:int -> HoareST int (fun _ -> True) (fun _ r _ -> r == x + 1)
let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1)
= f 0
open FStar.Monotonic.Pure
assume val g : int -> int -> PURE int (as_pure_wp (fun p -> forall x. p x))
let test2 () : HoareST int (fun _ -> True) (fun _ _ _ -> True)
= g 2 (f 0)
(*
// * In the polymonadic bind (PURE, HoareST) |> HoareST, the return type of
// * g is not allowed to depend on x, the return value of f
// *
// * So then what happens when a function f whose return type depends on its argument
// * is applied to a PURE term
// * NOTE: PURE and not Tot, since Tot will just be substituted,
// * without even invoking the bind
// *
// * When typechecking f e, the comp type is roughly
// * bind C_e C_ret_f, where C_ret_f is the comp type of f (below the arrow binder)
// * This is where bind comes in
// *)
assume type t_int (x:int) : Type0
assume val dep_f (x:int) : HoareST (t_int x) (fun _ -> True) (fun _ _ _ -> True)
assume val pure_g (_:unit) : PURE int (as_pure_wp (fun p -> forall (x:int). x >= 2 ==> p x))
let test_dep_f () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
dep_f (pure_g ())
(*
// * This works!
// *
// * The reason is that, before bind is called, the typechecker has already
// * substituted the pure term (pure_g ()) into the comp type of dep_f
// * (below the binder)
// *)
(*
// * But what happens when this is an explicit let binding?
// * as opposed to a function application
// *)
let test_dep_f2 () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
let x = pure_g () in
dep_f x
(*
// * This also works because weakening the type using the annotation saves us!
// *)
module Seq = FStar.Seq
type array (a:Type0) = ref (Seq.seq a)
let op_At_Bar (#a:Type0) (s1:array a) (s2:array a)
: HoareST (array a)
(fun _ -> True)
(fun h0 r h1 ->
sel h1 r == Seq.append (sel h0 s1) (sel h0 s2) /\
modifies Set.empty h0 h1)
= let s1 = !s1 in
let s2 = !s2 in
alloc (Seq.append s1 s2)
let index (#a:Type0) (x:array a) (i:nat)
: HoareST a
(fun h -> i < Seq.length (sel h x))
(fun h0 v h1 ->
i < Seq.length (sel h0 x) /\
h0 == h1 /\
v == Seq.index (sel h0 x) i)
= let s = !x in
Seq.index s i
let upd (#a:Type0) (x:array a) (i:nat) (v:a)
: HoareST unit
(fun h -> i < Seq.length (sel h x))
(fun h0 _ h1 ->
i < Seq.length (sel h0 x) /\
modifies (Set.singleton (addr_of x)) h0 h1 /\
sel h1 x == Seq.upd (sel h0 x) i v)
= let s = !x in
let s = Seq.upd s i v in
x := s
let length (#a:Type0) (x:array a)
: HoareST nat
(fun _ -> True)
(fun h0 y h1 -> y == Seq.length (sel h0 x) /\ h0 == h1)
= let s = !x in
Seq.length s
let swap (#a:Type0) (x:array a) (i:nat) (j:nat{i <= j})
: HoareST unit
(fun h -> j < Seq.length (sel h x))
(fun h0 _ h1 ->
j < Seq.length (sel h0 x) /\
modifies (Set.singleton (addr_of x)) h0 h1 /\
sel h1 x == Seq.swap (sel h0 x) i j)
= let v_i = index x i in
let v_j = index x j in
upd x j v_i;
upd x i v_j
/// `match` with PURE code in one branch and HoareST in another doesn't work
///
/// Since it requires lifts
///
/// Just writing `admit ()` at the end of a HoareST function also doesn't work for the same reason
/// But we can define a return combinator and use it | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> HoareSTPolyBind.HoareST a | HoareSTPolyBind.HoareST | [] | [] | [
"HoareSTPolyBind.returnc",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let return (#a: Type) (x: a) : HoareST a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1) =
| HoareST?.reflect (returnc a x) | false |
Vale.AES.GHash_s.fst | Vale.AES.GHash_s.gf128_mul_LE | val gf128_mul_LE (a_LE b_LE: quad32) : quad32 | val gf128_mul_LE (a_LE b_LE: quad32) : quad32 | let gf128_mul_LE (a_LE b_LE:quad32) : quad32 =
let a_BE = reverse_bytes_quad32 a_LE in
let b_BE = reverse_bytes_quad32 b_LE in
let ab_BE = gf128_to_quad32 (gf128_mul (gf128_of_quad32 a_BE) (gf128_of_quad32 b_BE)) in
reverse_bytes_quad32 ab_BE | {
"file_name": "vale/specs/crypto/Vale.AES.GHash_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 17,
"start_col": 0,
"start_line": 13
} | module Vale.AES.GHash_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.AES.GF128_s
open Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
type ghash_plain_LE:eqtype = s:seq quad32 { length s > 0 } | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GHash_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"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 | a_LE: Vale.Def.Types_s.quad32 -> b_LE: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.AES.GF128_s.gf128_to_quad32",
"Vale.AES.GF128_s.gf128_mul",
"Vale.AES.GF128_s.gf128_of_quad32"
] | [] | false | false | false | true | false | let gf128_mul_LE (a_LE b_LE: quad32) : quad32 =
| let a_BE = reverse_bytes_quad32 a_LE in
let b_BE = reverse_bytes_quad32 b_LE in
let ab_BE = gf128_to_quad32 (gf128_mul (gf128_of_quad32 a_BE) (gf128_of_quad32 b_BE)) in
reverse_bytes_quad32 ab_BE | false |
Vale.AES.GHash_s.fst | Vale.AES.GHash_s.ghash_LE | val ghash_LE : _: Vale.Def.Types_s.quad32 -> _: Vale.AES.GHash_s.ghash_plain_LE
-> Prims.Tot Vale.Def.Types_s.quad32 | let ghash_LE = opaque_make ghash_LE_def | {
"file_name": "vale/specs/crypto/Vale.AES.GHash_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 28,
"start_col": 19,
"start_line": 28
} | module Vale.AES.GHash_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.AES.GF128_s
open Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
type ghash_plain_LE:eqtype = s:seq quad32 { length s > 0 }
let gf128_mul_LE (a_LE b_LE:quad32) : quad32 =
let a_BE = reverse_bytes_quad32 a_LE in
let b_BE = reverse_bytes_quad32 b_LE in
let ab_BE = gf128_to_quad32 (gf128_mul (gf128_of_quad32 a_BE) (gf128_of_quad32 b_BE)) in
reverse_bytes_quad32 ab_BE
let rec ghash_LE_def (h_LE:quad32) (x:ghash_plain_LE) : Tot quad32 (decreases %[length x]) =
let y_i_minus_1 =
(if length x = 1 then
Mkfour 0 0 0 0
else
ghash_LE_def h_LE (all_but_last x)) in
let x_i = last x in
let xor_LE = quad32_xor y_i_minus_1 x_i in | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GHash_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"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 | _: Vale.Def.Types_s.quad32 -> _: Vale.AES.GHash_s.ghash_plain_LE
-> Prims.Tot Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"Vale.AES.GHash_s.ghash_plain_LE",
"Vale.AES.GHash_s.ghash_LE_def"
] | [] | false | false | false | true | false | let ghash_LE =
| opaque_make ghash_LE_def | false |
|
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_codegen_success_Keyhash_init | val va_codegen_success_Keyhash_init : win:bool -> alg:algorithm -> Tot va_pbool | val va_codegen_success_Keyhash_init : win:bool -> alg:algorithm -> Tot va_pbool | let va_codegen_success_Keyhash_init win alg =
(va_pbool_and (va_codegen_success_CreateHeaplets ()) (va_pbool_and
(va_codegen_success_InitPshufbMask (va_op_xmm_xmm 4) (va_op_reg_opr64_reg64 rR8)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 0)) (va_pbool_and (if win then va_pbool_and
(va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRdx)
(va_op_xmm_xmm 0) 80 Secret) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64
rR8) (va_op_opr64_reg64 rRcx)) (va_ttrue ())) else va_pbool_and
(va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRsi)
(va_op_xmm_xmm 0) 80 Secret) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64
rR8) (va_op_opr64_reg64 rRdi)) (va_ttrue ()))) (va_pbool_and
(va_codegen_success_AESEncryptBlock alg) (va_pbool_and (va_codegen_success_Pshufb
(va_op_xmm_xmm 0) (va_op_xmm_xmm 4)) (va_pbool_and (if win then va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rRdx)) (va_ttrue ())
else va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64
rRsi)) (va_ttrue ())) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 0) 32 Secret)
(va_pbool_and (va_codegen_success_Gf128_powers ()) (va_pbool_and
(va_codegen_success_DestroyHeaplets ()) (va_ttrue ()))))))))))) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 682,
"start_col": 0,
"start_line": 665
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f))
//--
//-- ShiftKey1_gf128_power
val va_code_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_gf128_power () =
(va_Block (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 4)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm
5)) (va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12))
(va_CCons (va_code_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (va_CCons
(va_code_ShiftKey1_128 ()) (va_CNil ()))))))))
val va_codegen_success_ShiftKey1_gf128_power : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_gf128_power () =
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 4)) (va_pbool_and
(va_codegen_success_ZeroXmm (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_PinsrdImm
(va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12))
(va_pbool_and (va_codegen_success_ShiftKey1_128 ()) (va_ttrue ())))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_gf128_power (va_mods:va_mods_t) (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 119 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 4)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 120 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ZeroXmm (va_op_xmm_xmm 5)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 121 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 3254779904 3 (va_op_reg_opr64_reg64 rR12)) (va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 122 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 4) 1 0 (va_op_reg_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 123 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PinsrdImm (va_op_xmm_xmm 5) 2147483648 3 (va_op_reg_opr64_reg64 rR12)) (fun
(va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 124 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_high_bit ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 125 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_gf128_low_shift_1 ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 127 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_128 gf128_modulus_low_terms) (fun (va_s:va_state) _ -> let
(va_arg16:Prims.nat) = n in let (va_arg15:Vale.Math.Poly2_s.poly) = h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 128 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_gf128_power va_arg15 va_arg16) (va_QEmpty (()))))))))))))
val va_lemma_ShiftKey1_gf128_power : va_b0:va_code -> va_s0:va_state -> h:poly -> n:nat
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_gf128_power ()) va_s0 /\ va_get_ok va_s0 /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) /\
va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0))))))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_gf128_power va_b0 va_s0 h n =
let (va_mods:va_mods_t) = [va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_gf128_power va_mods h n in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_gf128_power ()) va_qc va_s0
(fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 105 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in label va_range1
"***** POSTCONDITION NOT MET AT line 117 column 45 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags; va_Mod_ok]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_gf128_power (h:poly) (n:nat) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in avx_enabled /\ sse_enabled /\ hn == Vale.AES.GHash.g_power h n) /\
(forall (va_x_efl:Vale.X64.Flags.t) (va_x_r12:nat64) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) . let va_sM = va_upd_xmm 5 va_x_xmm5
(va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1
(va_upd_reg64 rR12 va_x_r12 (va_upd_flags va_x_efl va_s0)))))) in va_get_ok va_sM /\ (let
(hn:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GHash.gf128_power h n) ==>
va_k va_sM (())))
val va_wpProof_ShiftKey1_gf128_power : h:poly -> n:nat -> va_s0:va_state -> va_k:(va_state -> unit
-> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_gf128_power h n va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm
5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags])
va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_gf128_power h n va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_gf128_power (va_code_ShiftKey1_gf128_power ()) va_s0 h n
in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_reg64 rR12 va_sM (va_update_flags
va_sM (va_update_ok va_sM va_s0)))))))));
va_lemma_norm_mods ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1;
va_Mod_reg64 rR12; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_ShiftKey1_gf128_power (h:poly) (n:nat) : (va_quickCode unit
(va_code_ShiftKey1_gf128_power ())) =
(va_QProc (va_code_ShiftKey1_gf128_power ()) ([va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_reg64 rR12; va_Mod_flags]) (va_wp_ShiftKey1_gf128_power h n)
(va_wpProof_ShiftKey1_gf128_power h n))
//--
//-- Gf128_powers
val va_code_Gf128_powers : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Gf128_powers () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_CCons (va_code_Load128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64 rRcx) 32 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128
(va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons (va_code_ShiftKey1_gf128_power ()) (va_CCons
(va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1))
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_CCons
(va_code_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret) (va_CCons (va_code_Gf128MulRev128 ()) (va_CCons (va_code_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_CCons (va_code_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_CCons
(va_code_ShiftKey1_gf128_power ()) (va_CCons (va_code_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_CCons (va_code_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_CNil
()))))))))))))))))))))))))))))))))))))))))))))))
val va_codegen_success_Gf128_powers : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Gf128_powers () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm
6) (va_op_xmm_xmm 1)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm
1)) (va_pbool_and (va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and
(va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1)
(va_op_xmm_xmm 6)) (va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm
6)) (va_pbool_and (va_codegen_success_Gf128MulRev128 ()) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 16 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 48 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 64 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 96 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_pbool_and
(va_codegen_success_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1)
(va_op_reg_opr64_reg64 rRcx) 32 Secret) (va_pbool_and (va_codegen_success_Gf128MulRev128 ())
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_pbool_and
(va_codegen_success_ShiftKey1_gf128_power ()) (va_pbool_and (va_codegen_success_Store128_buffer
(va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 1) 112 Secret)
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_pbool_and
(va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_ttrue
())))))))))))))))))))))))))))))))))))))))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Gf128_powers (va_mods:va_mods_t) (h:poly) (hkeys_b:buffer128) : (va_quickCode unit
(va_code_Gf128_powers ())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 158 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 0) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 159 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rR12)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 161 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (fun (va_s:va_state) _ -> let (va_arg57:Vale.Math.Poly2_s.poly) = h
in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 162 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_1 va_arg57) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 163 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 164 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 165 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 166 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 0 Secret hkeys_b 0) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 168 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 169 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 170 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg56:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 171 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg56 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 172 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 173 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 174 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 175 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 16 Secret hkeys_b 1) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 177 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 178 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 179 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg55:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 180 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg55 2) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 181 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 182 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 183 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 184 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 48 Secret hkeys_b 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 186 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 187 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 188 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg54:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 189 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg54 3) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 190 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 191 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 192 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 193 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 64 Secret hkeys_b 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 195 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 196 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 197 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg53:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 198 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg53 4) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 199 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 200 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 201 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 5) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 202 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 96 Secret hkeys_b 6) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 204 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 2) (va_op_xmm_xmm 6)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 205 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Load128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_xmm_xmm 1) (va_op_reg_opr64_reg64
rRcx) 32 Secret hkeys_b 2) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 206 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Gf128MulRev128 ()) (fun (va_s:va_state) _ -> let (va_arg52:Vale.Math.Poly2_s.poly) =
h in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 207 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GHash.lemma_g_power_n va_arg52 5) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 208 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 209 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 3) (va_op_xmm_xmm 1)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 210 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftKey1_gf128_power h 6) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 211 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 1) 112 Secret hkeys_b 7) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 213 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 6) (va_op_xmm_xmm 0)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 214 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov64 (va_op_dst_opr64_reg64 rR12) (va_op_opr64_reg64 rRax)) (va_QEmpty
(())))))))))))))))))))))))))))))))))))))))))))))))))))))
val va_lemma_Gf128_powers : va_b0:va_code -> va_s0:va_state -> h:poly -> hkeys_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Gf128_powers ()) va_s0 /\ va_get_ok va_s0 /\
(pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRcx va_s0) hkeys_b 8 (va_get_mem_layout va_s0)
Secret /\ Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 2
(va_get_mem_heaplet 1 va_s0)) == h))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0
/\ Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 hkeys_b)
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 1 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 2 /\ Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 3 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 4 /\ Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 5 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 6 /\ va_state_eq va_sM (va_update_xmm 6 va_sM (va_update_xmm 5
va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1
va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rRax va_sM
(va_update_flags va_sM (va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM
va_s0)))))))))))))))
[@"opaque_to_smt"]
let va_lemma_Gf128_powers va_b0 va_s0 h hkeys_b =
let (va_mods:va_mods_t) = [va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_ok; va_Mod_mem] in
let va_qc = va_qcode_Gf128_powers va_mods h hkeys_b in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Gf128_powers ()) va_qc va_s0 (fun va_s0
va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 131 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 145 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 146 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 147 column 61 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 hkeys_b)
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 148 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 1) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 149 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 2) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 151 column 84 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 152 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 3) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 153 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 4) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 154 column 84 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_sM) ==
Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 155 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 5) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 156 column 74 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet
1 va_sM)) == Vale.AES.GHash.gf128_power h 6)) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_ok; va_Mod_mem]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_Gf128_powers (h:poly) (hkeys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit ->
Type0)) : Type0 =
(va_get_ok va_s0 /\ (pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg64 rRcx va_s0) hkeys_b
8 (va_get_mem_layout va_s0) Secret /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0)) == h /\ (forall
(va_x_mem:vale_heap) (va_x_heap1:vale_heap) (va_x_efl:Vale.X64.Flags.t) (va_x_rax:nat64)
(va_x_r12:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32)
(va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) . let va_sM = va_upd_xmm 6 va_x_xmm6
(va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rRax
va_x_rax (va_upd_flags va_x_efl (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem
va_s0))))))))))) in va_get_ok va_sM /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64
rR12 va_sM == va_get_reg64 rR12 va_s0 /\ Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer
#Vale.X64.Memory.vuint128 hkeys_b) (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 0 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 1 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 1 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 2 /\ Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 2 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 3 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 3 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 4 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 4 /\ Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1
va_sM) == Vale.X64.Decls.buffer128_read hkeys_b 5 (va_get_mem_heaplet 1 va_s0) /\
Vale.Math.Poly2.Bits_s.of_quad32 (Vale.X64.Decls.buffer128_read hkeys_b 6 (va_get_mem_heaplet 1
va_sM)) == Vale.AES.GHash.gf128_power h 5 /\ Vale.Math.Poly2.Bits_s.of_quad32
(Vale.X64.Decls.buffer128_read hkeys_b 7 (va_get_mem_heaplet 1 va_sM)) ==
Vale.AES.GHash.gf128_power h 6 ==> va_k va_sM (())))
val va_wpProof_Gf128_powers : h:poly -> hkeys_b:buffer128 -> va_s0:va_state -> va_k:(va_state ->
unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Gf128_powers h hkeys_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Gf128_powers ()) ([va_Mod_xmm 6;
va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0;
va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0
va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_Gf128_powers h hkeys_b va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Gf128_powers (va_code_Gf128_powers ()) va_s0 h hkeys_b in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM
(va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM
(va_update_reg64 rR12 va_sM (va_update_reg64 rRax va_sM (va_update_flags va_sM
(va_update_mem_heaplet 1 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))));
va_lemma_norm_mods ([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_mem]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_Gf128_powers (h:poly) (hkeys_b:buffer128) : (va_quickCode unit (va_code_Gf128_powers
())) =
(va_QProc (va_code_Gf128_powers ()) ([va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR12; va_Mod_reg64 rRax; va_Mod_flags;
va_Mod_mem_heaplet 1; va_Mod_mem]) (va_wp_Gf128_powers h hkeys_b) (va_wpProof_Gf128_powers h
hkeys_b))
//--
//-- Keyhash_init
[@ "opaque_to_smt" va_qattr]
let va_code_Keyhash_init win alg =
(va_Block (va_CCons (va_code_CreateHeaplets ()) (va_CCons (va_code_InitPshufbMask (va_op_xmm_xmm
4) (va_op_reg_opr64_reg64 rR8)) (va_CCons (va_code_ZeroXmm (va_op_xmm_xmm 0)) (va_CCons (if win
then va_Block (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRdx) (va_op_xmm_xmm 0) 80 Secret) (va_CCons (va_code_Mov64
(va_op_dst_opr64_reg64 rR8) (va_op_opr64_reg64 rRcx)) (va_CNil ()))) else va_Block (va_CCons
(va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1) (va_op_reg_opr64_reg64 rRsi)
(va_op_xmm_xmm 0) 80 Secret) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR8)
(va_op_opr64_reg64 rRdi)) (va_CNil ())))) (va_CCons (va_code_AESEncryptBlock alg) (va_CCons
(va_code_Pshufb (va_op_xmm_xmm 0) (va_op_xmm_xmm 4)) (va_CCons (if win then va_Block (va_CCons
(va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rRdx)) (va_CNil ())) else
va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_op_opr64_reg64 rRsi))
(va_CNil ()))) (va_CCons (va_code_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRcx) (va_op_xmm_xmm 0) 32 Secret) (va_CCons (va_code_Gf128_powers ())
(va_CCons (va_Block (va_CNil ())) (va_CCons (va_code_DestroyHeaplets ()) (va_CNil
()))))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | win: Prims.bool -> alg: Vale.AES.AES_common_s.algorithm -> Vale.X64.Decls.va_pbool | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.AES.AES_common_s.algorithm",
"Vale.X64.Decls.va_pbool_and",
"Vale.X64.InsMem.va_codegen_success_CreateHeaplets",
"Vale.X64.InsVector.va_codegen_success_InitPshufbMask",
"Vale.X64.Decls.va_op_xmm_xmm",
"Vale.X64.Decls.va_op_reg_opr64_reg64",
"Vale.X64.Machine_s.rR8",
"Vale.X64.InsVector.va_codegen_success_ZeroXmm",
"Vale.X64.InsVector.va_codegen_success_Store128_buffer",
"Vale.X64.Decls.va_op_heaplet_mem_heaplet",
"Vale.X64.Machine_s.rRdx",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.InsBasic.va_codegen_success_Mov64",
"Vale.X64.Decls.va_op_dst_opr64_reg64",
"Vale.X64.Decls.va_op_opr64_reg64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Decls.va_ttrue",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.Decls.va_pbool",
"Vale.AES.X64.AES.va_codegen_success_AESEncryptBlock",
"Vale.X64.InsVector.va_codegen_success_Pshufb",
"Vale.AES.X64.GF128_Init.va_codegen_success_Gf128_powers",
"Vale.X64.InsMem.va_codegen_success_DestroyHeaplets"
] | [] | false | false | false | true | false | let va_codegen_success_Keyhash_init win alg =
| (va_pbool_and (va_codegen_success_CreateHeaplets ())
(va_pbool_and (va_codegen_success_InitPshufbMask (va_op_xmm_xmm 4) (va_op_reg_opr64_reg64 rR8))
(va_pbool_and (va_codegen_success_ZeroXmm (va_op_xmm_xmm 0))
(va_pbool_and (if win
then
va_pbool_and (va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRdx)
(va_op_xmm_xmm 0)
80
Secret)
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR8)
(va_op_opr64_reg64 rRcx))
(va_ttrue ()))
else
va_pbool_and (va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet 1)
(va_op_reg_opr64_reg64 rRsi)
(va_op_xmm_xmm 0)
80
Secret)
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR8)
(va_op_opr64_reg64 rRdi))
(va_ttrue ())))
(va_pbool_and (va_codegen_success_AESEncryptBlock alg)
(va_pbool_and (va_codegen_success_Pshufb (va_op_xmm_xmm 0) (va_op_xmm_xmm 4))
(va_pbool_and (if win
then
va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx)
(va_op_opr64_reg64 rRdx))
(va_ttrue ())
else
va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx)
(va_op_opr64_reg64 rRsi))
(va_ttrue ()))
(va_pbool_and (va_codegen_success_Store128_buffer (va_op_heaplet_mem_heaplet
1)
(va_op_reg_opr64_reg64 rRcx)
(va_op_xmm_xmm 0)
32
Secret)
(va_pbool_and (va_codegen_success_Gf128_powers ())
(va_pbool_and (va_codegen_success_DestroyHeaplets ())
(va_ttrue ()))))))))))) | false |
Pulse.Checker.Prover.Substs.fsti | Pulse.Checker.Prover.Substs.nt_subst_st_term | val nt_subst_st_term (t: st_term) (ss: nt_substs) : st_term | val nt_subst_st_term (t: st_term) (ss: nt_substs) : st_term | let nt_subst_st_term (t:st_term) (ss:nt_substs) : st_term =
L.fold_left (fun t elt -> subst_st_term t [elt]) t ss | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Substs.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 55,
"end_line": 90,
"start_col": 0,
"start_line": 89
} | (*
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.Checker.Prover.Substs
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing.Env
open Pulse.Typing
module L = FStar.List.Tot
module T = FStar.Tactics
module Env = Pulse.Typing.Env
val ss_t : Type0
val ln_ss_t (s:ss_t) : bool
val as_map (ss:ss_t) : Map.t var term
let dom (ss:ss_t) = Map.domain (as_map ss)
let contains (ss:ss_t) (x:var) = Map.contains (as_map ss) x
let sel (ss:ss_t) (x:var { contains ss x }) = Map.sel (as_map ss) x
val empty : ss_t
val push (ss:ss_t) (x:var { ~ (contains ss x) }) (t:term) : ss_t
val push_ss (ss1:ss_t) (ss2:ss_t { Set.disjoint (dom ss1) (dom ss2) }) : ss_t
val check_disjoint (ss1 ss2:ss_t) : b:bool { b ==> Set.disjoint (dom ss1) (dom ss2) }
val diff (ss1 ss2:ss_t) : ss:ss_t { Set.disjoint (dom ss) (dom ss2) }
val push_as_map (ss1 ss2:ss_t)
: Lemma (requires Set.disjoint (dom ss1) (dom ss2))
(ensures as_map (push_ss ss1 ss2) == Map.concat (as_map ss1) (as_map ss2))
[SMTPat (as_map (push_ss ss1 ss2))]
val ss_term (t:term) (ss:ss_t) : term
val ss_st_term (t:st_term) (ss:ss_t) : st_term
val ss_st_comp (s:st_comp) (ss:ss_t) : st_comp
val ss_comp (c:comp) (ss:ss_t) : comp
val ss_binder (b:binder) (ss:ss_t) : binder
val ss_env (g:env) (ss:ss_t)
: g':env { fstar_env g' == fstar_env g /\
Env.dom g' == Env.dom g }
val ss_st_comp_commutes (s:st_comp) (ss:ss_t)
: Lemma (ensures
ss_st_comp s ss ==
{ s with res = ss_term s.res ss;
pre = ss_term s.pre ss;
post = ss_term s.post ss; }) // no shifting required
[SMTPat (ss_st_comp s ss)]
val ss_comp_commutes (c:comp) (ss:ss_t)
: Lemma (ensures
(let r = ss_comp c ss in
(C_Tot? c ==> r == C_Tot (ss_term (comp_res c) ss)) /\
(C_ST? c ==> r == C_ST (ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STAtomic? c ==> r == C_STAtomic (ss_term (comp_inames c) ss)
(C_STAtomic?.obs c)
(ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STGhost? c ==> r == C_STGhost (ss_st_comp (st_comp_of_comp c) ss))))
[SMTPat (ss_comp c ss)]
type nt_substs = l:list subst_elt { forall elt. L.memP elt l ==> NT? elt }
let nt_subst_term (t:term) (ss:nt_substs) : term =
L.fold_left (fun t elt -> subst_term t [elt]) t ss
let nt_subst_binder (b:binder) (ss:nt_substs) : binder =
L.fold_left (fun b elt -> subst_binder b [elt]) b ss | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Checker.Prover.Substs.fsti"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.st_term -> ss: Pulse.Checker.Prover.Substs.nt_substs
-> Pulse.Syntax.Base.st_term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Checker.Prover.Substs.nt_substs",
"FStar.List.Tot.Base.fold_left",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.subst_st_term",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let nt_subst_st_term (t: st_term) (ss: nt_substs) : st_term =
| L.fold_left (fun t elt -> subst_st_term t [elt]) t ss | false |
HoareSTPolyBind.fst | HoareSTPolyBind.subcomp | val subcomp
(a: Type)
(#pre_f: pre_t)
(#post_f: post_t a)
(#pre_g: pre_t)
(#post_g: post_t a)
(f: repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h: heap). pre_g h ==> pre_f h) /\
(forall (h0: heap) (h1: heap) (x: a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True) | val subcomp
(a: Type)
(#pre_f: pre_t)
(#post_f: post_t a)
(#pre_g: pre_t)
(#post_g: post_t a)
(f: repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h: heap). pre_g h ==> pre_f h) /\
(forall (h0: heap) (h1: heap) (x: a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True) | let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 73,
"start_col": 0,
"start_line": 64
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> f: HoareSTPolyBind.repr a pre_f post_f
-> Prims.Pure (HoareSTPolyBind.repr a pre_g post_g) | Prims.Pure | [] | [] | [
"HoareSTPolyBind.pre_t",
"HoareSTPolyBind.post_t",
"HoareSTPolyBind.repr",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Monotonic.Heap.heap",
"Prims.l_imp",
"Prims.l_True"
] | [] | false | false | false | false | false | let subcomp
(a: Type)
(#pre_f: pre_t)
(#post_f: post_t a)
(#pre_g: pre_t)
(#post_g: post_t a)
(f: repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h: heap). pre_g h ==> pre_f h) /\
(forall (h0: heap) (h1: heap) (x: a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True) =
| f | false |
HoareSTPolyBind.fst | HoareSTPolyBind.op_Bang | val ( ! ) (#a: Type) (#rel: P.preorder a) (r: mref a rel)
: HoareST a (fun _ -> True) (fun h0 x h1 -> h0 == h1 /\ x == sel h1 r) | val ( ! ) (#a: Type) (#rel: P.preorder a) (r: mref a rel)
: HoareST a (fun _ -> True) (fun h0 x h1 -> h0 == h1 /\ x == sel h1 r) | let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r) | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 122,
"start_col": 0,
"start_line": 116
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.ST.mref a rel -> HoareSTPolyBind.HoareST a | HoareSTPolyBind.HoareST | [] | [] | [
"FStar.Preorder.preorder",
"FStar.ST.mref",
"Prims.unit",
"FStar.ST.read",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.Heap.sel"
] | [] | false | true | false | false | false | let ( ! ) (#a: Type) (#rel: P.preorder a) (r: mref a rel)
: HoareST a (fun _ -> True) (fun h0 x h1 -> h0 == h1 /\ x == sel h1 r) =
| HoareST?.reflect (fun _ -> read r) | false |
Pulse.Checker.Prover.Substs.fsti | Pulse.Checker.Prover.Substs.nt_subst_st_comp | val nt_subst_st_comp (s: st_comp) (ss: nt_substs) : st_comp | val nt_subst_st_comp (s: st_comp) (ss: nt_substs) : st_comp | let nt_subst_st_comp (s:st_comp) (ss:nt_substs) : st_comp =
L.fold_left (fun s elt -> subst_st_comp s [elt]) s ss | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Substs.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 55,
"end_line": 93,
"start_col": 0,
"start_line": 92
} | (*
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.Checker.Prover.Substs
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing.Env
open Pulse.Typing
module L = FStar.List.Tot
module T = FStar.Tactics
module Env = Pulse.Typing.Env
val ss_t : Type0
val ln_ss_t (s:ss_t) : bool
val as_map (ss:ss_t) : Map.t var term
let dom (ss:ss_t) = Map.domain (as_map ss)
let contains (ss:ss_t) (x:var) = Map.contains (as_map ss) x
let sel (ss:ss_t) (x:var { contains ss x }) = Map.sel (as_map ss) x
val empty : ss_t
val push (ss:ss_t) (x:var { ~ (contains ss x) }) (t:term) : ss_t
val push_ss (ss1:ss_t) (ss2:ss_t { Set.disjoint (dom ss1) (dom ss2) }) : ss_t
val check_disjoint (ss1 ss2:ss_t) : b:bool { b ==> Set.disjoint (dom ss1) (dom ss2) }
val diff (ss1 ss2:ss_t) : ss:ss_t { Set.disjoint (dom ss) (dom ss2) }
val push_as_map (ss1 ss2:ss_t)
: Lemma (requires Set.disjoint (dom ss1) (dom ss2))
(ensures as_map (push_ss ss1 ss2) == Map.concat (as_map ss1) (as_map ss2))
[SMTPat (as_map (push_ss ss1 ss2))]
val ss_term (t:term) (ss:ss_t) : term
val ss_st_term (t:st_term) (ss:ss_t) : st_term
val ss_st_comp (s:st_comp) (ss:ss_t) : st_comp
val ss_comp (c:comp) (ss:ss_t) : comp
val ss_binder (b:binder) (ss:ss_t) : binder
val ss_env (g:env) (ss:ss_t)
: g':env { fstar_env g' == fstar_env g /\
Env.dom g' == Env.dom g }
val ss_st_comp_commutes (s:st_comp) (ss:ss_t)
: Lemma (ensures
ss_st_comp s ss ==
{ s with res = ss_term s.res ss;
pre = ss_term s.pre ss;
post = ss_term s.post ss; }) // no shifting required
[SMTPat (ss_st_comp s ss)]
val ss_comp_commutes (c:comp) (ss:ss_t)
: Lemma (ensures
(let r = ss_comp c ss in
(C_Tot? c ==> r == C_Tot (ss_term (comp_res c) ss)) /\
(C_ST? c ==> r == C_ST (ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STAtomic? c ==> r == C_STAtomic (ss_term (comp_inames c) ss)
(C_STAtomic?.obs c)
(ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STGhost? c ==> r == C_STGhost (ss_st_comp (st_comp_of_comp c) ss))))
[SMTPat (ss_comp c ss)]
type nt_substs = l:list subst_elt { forall elt. L.memP elt l ==> NT? elt }
let nt_subst_term (t:term) (ss:nt_substs) : term =
L.fold_left (fun t elt -> subst_term t [elt]) t ss
let nt_subst_binder (b:binder) (ss:nt_substs) : binder =
L.fold_left (fun b elt -> subst_binder b [elt]) b ss
let nt_subst_st_term (t:st_term) (ss:nt_substs) : st_term =
L.fold_left (fun t elt -> subst_st_term t [elt]) t ss | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Checker.Prover.Substs.fsti"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Pulse.Syntax.Base.st_comp -> ss: Pulse.Checker.Prover.Substs.nt_substs
-> Pulse.Syntax.Base.st_comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.st_comp",
"Pulse.Checker.Prover.Substs.nt_substs",
"FStar.List.Tot.Base.fold_left",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.subst_st_comp",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let nt_subst_st_comp (s: st_comp) (ss: nt_substs) : st_comp =
| L.fold_left (fun s elt -> subst_st_comp s [elt]) s ss | false |
HoareSTPolyBind.fst | HoareSTPolyBind.bind_hoarest_pure | val bind_hoarest_pure
(a b: Type)
(req: pre_t)
(ens: post_t a)
(wp: (a -> pure_wp b))
(f: repr a req ens)
(g: (x: a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~((wp x) (fun y -> y =!= r)))) | val bind_hoarest_pure
(a b: Type)
(req: pre_t)
(ens: post_t a)
(wp: (a -> pure_wp b))
(f: repr a req ens)
(g: (x: a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~((wp x) (fun y -> y =!= r)))) | let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) () | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 10,
"end_line": 166,
"start_col": 0,
"start_line": 158
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
b: Type ->
req: HoareSTPolyBind.pre_t ->
ens: HoareSTPolyBind.post_t a ->
wp: (_: a -> Prims.pure_wp b) ->
f: HoareSTPolyBind.repr a req ens ->
g: (x: a -> _: Prims.unit -> Prims.PURE b)
-> HoareSTPolyBind.repr b
(fun h ->
req h /\
(forall (x: a) (h1: FStar.Monotonic.Heap.heap).
ens h x h1 ==> wp x (fun _ -> Prims.l_True)))
(fun h0 r h1 -> exists (x: a). ens h0 x h1 /\ ~(wp x (fun y -> ~(y == r)))) | Prims.Tot | [
"total"
] | [] | [
"HoareSTPolyBind.pre_t",
"HoareSTPolyBind.post_t",
"Prims.pure_wp",
"HoareSTPolyBind.repr",
"Prims.unit",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall",
"FStar.Monotonic.Heap.heap",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_True",
"Prims.l_Exists",
"Prims.l_not",
"Prims.eq2"
] | [] | false | false | false | false | false | let bind_hoarest_pure
(a b: Type)
(req: pre_t)
(ens: post_t a)
(wp: (a -> pure_wp b))
(f: repr a req ens)
(g: (x: a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~((wp x) (fun y -> y =!= r)))) =
| FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) () | false |
HoareSTPolyBind.fst | HoareSTPolyBind.test_subcomp3 | val test_subcomp3 (n: int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) | val test_subcomp3 (n: int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) | let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 95,
"end_line": 194,
"start_col": 0,
"start_line": 194
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.int -> HoareSTPolyBind.HoareST Prims.int | HoareSTPolyBind.HoareST | [] | [] | [
"Prims.int",
"HoareSTPolyBind.f_test_subcomp",
"FStar.Monotonic.Heap.heap",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.l_True"
] | [] | false | true | false | false | false | let test_subcomp3 (n: int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) =
| f_test_subcomp n | false |
Hacl.Bignum256_32.fsti | Hacl.Bignum256_32.t_limbs | val t_limbs:Hacl.Bignum.Definitions.limb_t | val t_limbs:Hacl.Bignum.Definitions.limb_t | let t_limbs: Hacl.Bignum.Definitions.limb_t = Lib.IntTypes.U32 | {
"file_name": "code/bignum/Hacl.Bignum256_32.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 12,
"start_col": 0,
"start_line": 12
} | module Hacl.Bignum256_32
open FStar.Mul
module BN = Hacl.Bignum
module BS = Hacl.Bignum.SafeAPI
module MA = Hacl.Bignum.MontArithmetic
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Bignum.SafeAPI.fst.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum256_32.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.SafeAPI",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Bignum.Definitions.limb_t | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.U32"
] | [] | false | false | false | true | false | let t_limbs:Hacl.Bignum.Definitions.limb_t =
| Lib.IntTypes.U32 | false |
Pulse.Checker.Prover.Substs.fsti | Pulse.Checker.Prover.Substs.nt_subst_binder | val nt_subst_binder (b: binder) (ss: nt_substs) : binder | val nt_subst_binder (b: binder) (ss: nt_substs) : binder | let nt_subst_binder (b:binder) (ss:nt_substs) : binder =
L.fold_left (fun b elt -> subst_binder b [elt]) b ss | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Substs.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 87,
"start_col": 0,
"start_line": 86
} | (*
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.Checker.Prover.Substs
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing.Env
open Pulse.Typing
module L = FStar.List.Tot
module T = FStar.Tactics
module Env = Pulse.Typing.Env
val ss_t : Type0
val ln_ss_t (s:ss_t) : bool
val as_map (ss:ss_t) : Map.t var term
let dom (ss:ss_t) = Map.domain (as_map ss)
let contains (ss:ss_t) (x:var) = Map.contains (as_map ss) x
let sel (ss:ss_t) (x:var { contains ss x }) = Map.sel (as_map ss) x
val empty : ss_t
val push (ss:ss_t) (x:var { ~ (contains ss x) }) (t:term) : ss_t
val push_ss (ss1:ss_t) (ss2:ss_t { Set.disjoint (dom ss1) (dom ss2) }) : ss_t
val check_disjoint (ss1 ss2:ss_t) : b:bool { b ==> Set.disjoint (dom ss1) (dom ss2) }
val diff (ss1 ss2:ss_t) : ss:ss_t { Set.disjoint (dom ss) (dom ss2) }
val push_as_map (ss1 ss2:ss_t)
: Lemma (requires Set.disjoint (dom ss1) (dom ss2))
(ensures as_map (push_ss ss1 ss2) == Map.concat (as_map ss1) (as_map ss2))
[SMTPat (as_map (push_ss ss1 ss2))]
val ss_term (t:term) (ss:ss_t) : term
val ss_st_term (t:st_term) (ss:ss_t) : st_term
val ss_st_comp (s:st_comp) (ss:ss_t) : st_comp
val ss_comp (c:comp) (ss:ss_t) : comp
val ss_binder (b:binder) (ss:ss_t) : binder
val ss_env (g:env) (ss:ss_t)
: g':env { fstar_env g' == fstar_env g /\
Env.dom g' == Env.dom g }
val ss_st_comp_commutes (s:st_comp) (ss:ss_t)
: Lemma (ensures
ss_st_comp s ss ==
{ s with res = ss_term s.res ss;
pre = ss_term s.pre ss;
post = ss_term s.post ss; }) // no shifting required
[SMTPat (ss_st_comp s ss)]
val ss_comp_commutes (c:comp) (ss:ss_t)
: Lemma (ensures
(let r = ss_comp c ss in
(C_Tot? c ==> r == C_Tot (ss_term (comp_res c) ss)) /\
(C_ST? c ==> r == C_ST (ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STAtomic? c ==> r == C_STAtomic (ss_term (comp_inames c) ss)
(C_STAtomic?.obs c)
(ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STGhost? c ==> r == C_STGhost (ss_st_comp (st_comp_of_comp c) ss))))
[SMTPat (ss_comp c ss)]
type nt_substs = l:list subst_elt { forall elt. L.memP elt l ==> NT? elt }
let nt_subst_term (t:term) (ss:nt_substs) : term =
L.fold_left (fun t elt -> subst_term t [elt]) t ss | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Checker.Prover.Substs.fsti"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Pulse.Syntax.Base.binder -> ss: Pulse.Checker.Prover.Substs.nt_substs -> Pulse.Syntax.Base.binder | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.binder",
"Pulse.Checker.Prover.Substs.nt_substs",
"FStar.List.Tot.Base.fold_left",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.subst_binder",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let nt_subst_binder (b: binder) (ss: nt_substs) : binder =
| L.fold_left (fun b elt -> subst_binder b [elt]) b ss | false |
HoareSTPolyBind.fst | HoareSTPolyBind.bind_pure_hoarest | val bind_pure_hoarest
(a b: Type)
(wp: pure_wp a)
(req: (a -> pre_t))
(ens: (a -> post_t b))
(f: (unit -> PURE a wp))
(g: (x: a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~(wp (fun r -> r =!= x))) /\ ens x h0 r h1) | val bind_pure_hoarest
(a b: Type)
(wp: pure_wp a)
(req: (a -> pre_t))
(ens: (a -> post_t b))
(f: (unit -> PURE a wp))
(g: (x: a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~(wp (fun r -> r =!= x))) /\ ens x h0 r h1) | let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x () | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 8,
"end_line": 152,
"start_col": 0,
"start_line": 144
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
b: Type ->
wp: Prims.pure_wp a ->
req: (_: a -> HoareSTPolyBind.pre_t) ->
ens: (_: a -> HoareSTPolyBind.post_t b) ->
f: (_: Prims.unit -> Prims.PURE a) ->
g: (x: a -> HoareSTPolyBind.repr b (req x) (ens x))
-> HoareSTPolyBind.repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists (x: _: a{Prims.l_True}). ~(wp (fun r -> ~(r == x))) /\ ens x h0 r h1) | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"HoareSTPolyBind.pre_t",
"HoareSTPolyBind.post_t",
"Prims.unit",
"HoareSTPolyBind.repr",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_Exists",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2"
] | [] | false | false | false | false | false | let bind_pure_hoarest
(a b: Type)
(wp: pure_wp a)
(req: (a -> pre_t))
(ens: (a -> post_t b))
(f: (unit -> PURE a wp))
(g: (x: a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~(wp (fun r -> r =!= x))) /\ ens x h0 r h1) =
| FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x () | false |
HoareSTPolyBind.fst | HoareSTPolyBind.op_Colon_Equals | val ( := ) (#a: Type) (#rel: P.preorder a) (r: mref a rel) (x: a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 -> modifies (Set.singleton (addr_of r)) h0 h1 /\ equal_dom h0 h1 /\ sel h1 r == x
) | val ( := ) (#a: Type) (#rel: P.preorder a) (r: mref a rel) (x: a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 -> modifies (Set.singleton (addr_of r)) h0 h1 /\ equal_dom h0 h1 /\ sel h1 r == x
) | let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x) | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 131,
"start_col": 0,
"start_line": 124
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.ST.mref a rel -> x: a -> HoareSTPolyBind.HoareST Prims.unit | HoareSTPolyBind.HoareST | [] | [] | [
"FStar.Preorder.preorder",
"FStar.ST.mref",
"Prims.unit",
"FStar.ST.write",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.Heap.sel",
"Prims.l_and",
"FStar.Monotonic.Heap.modifies",
"FStar.Set.singleton",
"Prims.nat",
"FStar.Monotonic.Heap.addr_of",
"FStar.Monotonic.Heap.equal_dom",
"Prims.eq2"
] | [] | false | true | false | false | false | let ( := ) (#a: Type) (#rel: P.preorder a) (r: mref a rel) (x: a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 -> modifies (Set.singleton (addr_of r)) h0 h1 /\ equal_dom h0 h1 /\ sel h1 r == x
) =
| HoareST?.reflect (fun _ -> write r x) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.test_subcomp | val test_subcomp: Prims.unit -> HoareST int (fun _ -> True) (fun _ r _ -> r == 0) | val test_subcomp: Prims.unit -> HoareST int (fun _ -> True) (fun _ r _ -> r == 0) | let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0 | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 187,
"start_col": 0,
"start_line": 187
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> HoareSTPolyBind.HoareST Prims.int | HoareSTPolyBind.HoareST | [] | [] | [
"Prims.unit",
"Prims.int",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.eq2"
] | [] | false | true | false | false | false | let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) =
| 0 | false |
Pulse.Checker.Prover.Substs.fsti | Pulse.Checker.Prover.Substs.nt_subst_comp | val nt_subst_comp (c: comp) (ss: nt_substs) : comp | val nt_subst_comp (c: comp) (ss: nt_substs) : comp | let nt_subst_comp (c:comp) (ss:nt_substs) : comp =
L.fold_left (fun c elt -> subst_comp c [elt]) c ss | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Substs.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 52,
"end_line": 96,
"start_col": 0,
"start_line": 95
} | (*
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.Checker.Prover.Substs
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing.Env
open Pulse.Typing
module L = FStar.List.Tot
module T = FStar.Tactics
module Env = Pulse.Typing.Env
val ss_t : Type0
val ln_ss_t (s:ss_t) : bool
val as_map (ss:ss_t) : Map.t var term
let dom (ss:ss_t) = Map.domain (as_map ss)
let contains (ss:ss_t) (x:var) = Map.contains (as_map ss) x
let sel (ss:ss_t) (x:var { contains ss x }) = Map.sel (as_map ss) x
val empty : ss_t
val push (ss:ss_t) (x:var { ~ (contains ss x) }) (t:term) : ss_t
val push_ss (ss1:ss_t) (ss2:ss_t { Set.disjoint (dom ss1) (dom ss2) }) : ss_t
val check_disjoint (ss1 ss2:ss_t) : b:bool { b ==> Set.disjoint (dom ss1) (dom ss2) }
val diff (ss1 ss2:ss_t) : ss:ss_t { Set.disjoint (dom ss) (dom ss2) }
val push_as_map (ss1 ss2:ss_t)
: Lemma (requires Set.disjoint (dom ss1) (dom ss2))
(ensures as_map (push_ss ss1 ss2) == Map.concat (as_map ss1) (as_map ss2))
[SMTPat (as_map (push_ss ss1 ss2))]
val ss_term (t:term) (ss:ss_t) : term
val ss_st_term (t:st_term) (ss:ss_t) : st_term
val ss_st_comp (s:st_comp) (ss:ss_t) : st_comp
val ss_comp (c:comp) (ss:ss_t) : comp
val ss_binder (b:binder) (ss:ss_t) : binder
val ss_env (g:env) (ss:ss_t)
: g':env { fstar_env g' == fstar_env g /\
Env.dom g' == Env.dom g }
val ss_st_comp_commutes (s:st_comp) (ss:ss_t)
: Lemma (ensures
ss_st_comp s ss ==
{ s with res = ss_term s.res ss;
pre = ss_term s.pre ss;
post = ss_term s.post ss; }) // no shifting required
[SMTPat (ss_st_comp s ss)]
val ss_comp_commutes (c:comp) (ss:ss_t)
: Lemma (ensures
(let r = ss_comp c ss in
(C_Tot? c ==> r == C_Tot (ss_term (comp_res c) ss)) /\
(C_ST? c ==> r == C_ST (ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STAtomic? c ==> r == C_STAtomic (ss_term (comp_inames c) ss)
(C_STAtomic?.obs c)
(ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STGhost? c ==> r == C_STGhost (ss_st_comp (st_comp_of_comp c) ss))))
[SMTPat (ss_comp c ss)]
type nt_substs = l:list subst_elt { forall elt. L.memP elt l ==> NT? elt }
let nt_subst_term (t:term) (ss:nt_substs) : term =
L.fold_left (fun t elt -> subst_term t [elt]) t ss
let nt_subst_binder (b:binder) (ss:nt_substs) : binder =
L.fold_left (fun b elt -> subst_binder b [elt]) b ss
let nt_subst_st_term (t:st_term) (ss:nt_substs) : st_term =
L.fold_left (fun t elt -> subst_st_term t [elt]) t ss
let nt_subst_st_comp (s:st_comp) (ss:nt_substs) : st_comp =
L.fold_left (fun s elt -> subst_st_comp s [elt]) s ss | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Checker.Prover.Substs.fsti"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Pulse.Syntax.Base.comp -> ss: Pulse.Checker.Prover.Substs.nt_substs -> Pulse.Syntax.Base.comp | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp",
"Pulse.Checker.Prover.Substs.nt_substs",
"FStar.List.Tot.Base.fold_left",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.subst_comp",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let nt_subst_comp (c: comp) (ss: nt_substs) : comp =
| L.fold_left (fun c elt -> subst_comp c [elt]) c ss | false |
HoareSTPolyBind.fst | HoareSTPolyBind.alloc | val alloc (#a: Type) (#rel: P.preorder a) (init: a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 -> fresh r h0 h1 /\ modifies Set.empty h0 h1 /\ sel h1 r == init) | val alloc (#a: Type) (#rel: P.preorder a) (init: a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 -> fresh r h0 h1 /\ modifies Set.empty h0 h1 /\ sel h1 r == init) | let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init) | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 114,
"start_col": 0,
"start_line": 107
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | init: a -> HoareSTPolyBind.HoareST (FStar.ST.mref a rel) | HoareSTPolyBind.HoareST | [] | [] | [
"FStar.Preorder.preorder",
"Prims.unit",
"FStar.ST.alloc",
"FStar.ST.mref",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_and",
"FStar.Monotonic.Heap.fresh",
"FStar.Monotonic.Heap.modifies",
"FStar.Set.empty",
"Prims.nat",
"Prims.eq2",
"FStar.Monotonic.Heap.sel"
] | [] | false | true | false | false | false | let alloc (#a: Type) (#rel: P.preorder a) (init: a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 -> fresh r h0 h1 /\ modifies Set.empty h0 h1 /\ sel h1 r == init) =
| HoareST?.reflect (fun _ -> alloc init) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.subcomp_pure_hoarest | val subcomp_pure_hoarest
(a: Type)
(wp: pure_wp a)
(req: pre_t)
(ens: post_t a)
(f: (unit -> PURE a wp))
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~(wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True) | val subcomp_pure_hoarest
(a: Type)
(wp: pure_wp a)
(req: pre_t)
(ens: post_t a)
(f: (unit -> PURE a wp))
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~(wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True) | let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f () | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 15,
"end_line": 183,
"start_col": 0,
"start_line": 175
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
wp: Prims.pure_wp a ->
req: HoareSTPolyBind.pre_t ->
ens: HoareSTPolyBind.post_t a ->
f: (_: Prims.unit -> Prims.PURE a)
-> Prims.Pure (HoareSTPolyBind.repr a req ens) | Prims.Pure | [] | [] | [
"Prims.pure_wp",
"HoareSTPolyBind.pre_t",
"HoareSTPolyBind.post_t",
"Prims.unit",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall",
"HoareSTPolyBind.repr",
"Prims.l_and",
"Prims.l_Forall",
"FStar.Monotonic.Heap.heap",
"Prims.l_imp",
"Prims.l_True",
"Prims.l_not",
"Prims.l_or",
"Prims.eq2"
] | [] | false | false | false | false | false | let subcomp_pure_hoarest
(a: Type)
(wp: pure_wp a)
(req: pre_t)
(ens: post_t a)
(f: (unit -> PURE a wp))
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~(wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True) =
| FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f () | false |
Vale.AES.X64.GF128_Init.fst | Vale.AES.X64.GF128_Init.va_quick_ShiftKey1_128 | val va_quick_ShiftKey1_128 (f: poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) | val va_quick_ShiftKey1_128 (f: poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) | let va_quick_ShiftKey1_128 (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
(va_QProc (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f) (va_wpProof_ShiftKey1_128 f)) | {
"file_name": "obj/Vale.AES.X64.GF128_Init.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 167,
"start_col": 0,
"start_line": 165
} | module Vale.AES.X64.GF128_Init
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash
open Vale.AES.AES_s
open Vale.AES.AES256_helpers
open Vale.AES.X64.AES
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.AES.X64.PolyOps
open Vale.AES.X64.GF128_Mul
open Vale.AES.GHash
open Vale.AES.OptPublic
//-- ShiftKey1_128
val va_code_ShiftKey1_128 : va_dummy:unit -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_ShiftKey1_128 () =
(va_Block (va_CCons (va_code_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_CCons
(va_code_ShiftLeft128_1 ()) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5))
(va_CCons (va_code_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_CCons (va_code_Pshufd
(va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (va_CCons (va_code_PolyAnd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 4)) (va_CCons (va_code_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_CNil ())))))))))
val va_codegen_success_ShiftKey1_128 : va_dummy:unit -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_ShiftKey1_128 () =
(va_pbool_and (va_codegen_success_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_pbool_and
(va_codegen_success_ShiftLeft128_1 ()) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm
3) (va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pcmpeqd (va_op_xmm_xmm 3)
(va_op_xmm_xmm 5)) (va_pbool_and (va_codegen_success_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3)
255) (va_pbool_and (va_codegen_success_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4))
(va_pbool_and (va_codegen_success_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1)
(va_op_opr128_xmm 3)) (va_ttrue ()))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_ShiftKey1_128 (va_mods:va_mods_t) (f:poly) : (va_quickCode unit (va_code_ShiftKey1_128
())) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s) in
va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 87 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Mov128 (va_op_xmm_xmm 1) (va_op_xmm_xmm 3)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 88 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_ShiftLeft128_1 h) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 89 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Bits.lemma_of_to_quad32_mask h1) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 90 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.lemma_shift_define_i h 1 128) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 92 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 93 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pcmpeqd (va_op_xmm_xmm 3) (va_op_xmm_xmm 5)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 94 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.AES.GF128.lemma_test_high_bit h) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 95 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_Pshufd (va_op_xmm_xmm 3) (va_op_xmm_xmm 3) 255) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 96 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_zero ()) (va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 97 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Words.lemma_quad32_ones ()) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_PolyAnd (va_op_xmm_xmm 3) (va_op_xmm_xmm 4)) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 101 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(fun (_:unit) -> Vale.Math.Poly2.Lemmas.lemma_and_consts ()) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 102 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_quick_VPolyAdd (va_op_xmm_xmm 1) (va_op_xmm_xmm 1) (va_op_opr128_xmm 3)) (va_QEmpty
(()))))))))))))))))
val va_lemma_ShiftKey1_128 : va_b0:va_code -> va_s0:va_state -> f:poly
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ShiftKey1_128 ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let
(h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) /\
va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0)))))))
[@"opaque_to_smt"]
let va_lemma_ShiftKey1_128 va_b0 va_s0 f =
let (va_mods:va_mods_t) = [va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok] in
let va_qc = va_qcode_ShiftKey1_128 va_mods f in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_ShiftKey1_128 ()) va_qc va_s0 (fun
va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 68 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(va_get_ok va_sM) /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
label va_range1
"***** POSTCONDITION NOT MET AT line 85 column 50 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/crypto/aes/x64/Vale.AES.X64.GF128_Init.vaf *****"
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h)))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags; va_Mod_ok]) va_sM
va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_ShiftKey1_128 (f:poly) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2_s.shift h 1 in let
(offset:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in
avx_enabled /\ sse_enabled /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 5 va_s0) ==
Vale.Math.Poly2_s.monomial 127 /\ offset == Vale.Math.Poly2_s.reverse (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2_s.add (Vale.Math.Poly2_s.monomial 128) f) (-1)) 127) /\ (forall
(va_x_efl:Vale.X64.Flags.t) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) . let
va_sM = va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_flags
va_x_efl va_s0))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 3 va_s0) in let (h1:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2_s.shift h 1 in let (offset:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_xmm 4 va_s0) in Vale.Math.Poly2.Bits_s.of_quad32
(va_get_xmm 1 va_sM) == Vale.AES.GF128.shift_key_1 128 f h) ==> va_k va_sM (())))
val va_wpProof_ShiftKey1_128 : f:poly -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ShiftKey1_128 f va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ShiftKey1_128 ()) ([va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_ShiftKey1_128 f va_s0 va_k =
let (va_sM, va_f0) = va_lemma_ShiftKey1_128 (va_code_ShiftKey1_128 ()) va_s0 f in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_flags va_sM (va_update_ok va_sM va_s0))))));
va_lemma_norm_mods ([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Words.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.X64.PolyOps.fsti.checked",
"Vale.AES.X64.GF128_Mul.fsti.checked",
"Vale.AES.X64.AES.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES_common_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.X64.GF128_Init.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Vale.Math.Poly2_s.poly
-> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.AES.X64.GF128_Init.va_code_ShiftKey1_128 ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.Math.Poly2_s.poly",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.X64.GF128_Init.va_code_ShiftKey1_128",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_xmm",
"Vale.X64.QuickCode.va_Mod_flags",
"Prims.Nil",
"Vale.AES.X64.GF128_Init.va_wp_ShiftKey1_128",
"Vale.AES.X64.GF128_Init.va_wpProof_ShiftKey1_128",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_ShiftKey1_128 (f: poly) : (va_quickCode unit (va_code_ShiftKey1_128 ())) =
| (va_QProc (va_code_ShiftKey1_128 ())
([va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_flags])
(va_wp_ShiftKey1_128 f)
(va_wpProof_ShiftKey1_128 f)) | false |
HoareSTPolyBind.fst | HoareSTPolyBind.length | val length (#a: Type0) (x: array a)
: HoareST nat (fun _ -> True) (fun h0 y h1 -> y == Seq.length (sel h0 x) /\ h0 == h1) | val length (#a: Type0) (x: array a)
: HoareST nat (fun _ -> True) (fun h0 y h1 -> y == Seq.length (sel h0 x) /\ h0 == h1) | let length (#a:Type0) (x:array a)
: HoareST nat
(fun _ -> True)
(fun h0 y h1 -> y == Seq.length (sel h0 x) /\ h0 == h1)
= let s = !x in
Seq.length s | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 14,
"end_line": 298,
"start_col": 0,
"start_line": 293
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n
let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n
assume val f : x:int -> HoareST int (fun _ -> True) (fun _ r _ -> r == x + 1)
let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1)
= f 0
open FStar.Monotonic.Pure
assume val g : int -> int -> PURE int (as_pure_wp (fun p -> forall x. p x))
let test2 () : HoareST int (fun _ -> True) (fun _ _ _ -> True)
= g 2 (f 0)
(*
// * In the polymonadic bind (PURE, HoareST) |> HoareST, the return type of
// * g is not allowed to depend on x, the return value of f
// *
// * So then what happens when a function f whose return type depends on its argument
// * is applied to a PURE term
// * NOTE: PURE and not Tot, since Tot will just be substituted,
// * without even invoking the bind
// *
// * When typechecking f e, the comp type is roughly
// * bind C_e C_ret_f, where C_ret_f is the comp type of f (below the arrow binder)
// * This is where bind comes in
// *)
assume type t_int (x:int) : Type0
assume val dep_f (x:int) : HoareST (t_int x) (fun _ -> True) (fun _ _ _ -> True)
assume val pure_g (_:unit) : PURE int (as_pure_wp (fun p -> forall (x:int). x >= 2 ==> p x))
let test_dep_f () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
dep_f (pure_g ())
(*
// * This works!
// *
// * The reason is that, before bind is called, the typechecker has already
// * substituted the pure term (pure_g ()) into the comp type of dep_f
// * (below the binder)
// *)
(*
// * But what happens when this is an explicit let binding?
// * as opposed to a function application
// *)
let test_dep_f2 () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
let x = pure_g () in
dep_f x
(*
// * This also works because weakening the type using the annotation saves us!
// *)
module Seq = FStar.Seq
type array (a:Type0) = ref (Seq.seq a)
let op_At_Bar (#a:Type0) (s1:array a) (s2:array a)
: HoareST (array a)
(fun _ -> True)
(fun h0 r h1 ->
sel h1 r == Seq.append (sel h0 s1) (sel h0 s2) /\
modifies Set.empty h0 h1)
= let s1 = !s1 in
let s2 = !s2 in
alloc (Seq.append s1 s2)
let index (#a:Type0) (x:array a) (i:nat)
: HoareST a
(fun h -> i < Seq.length (sel h x))
(fun h0 v h1 ->
i < Seq.length (sel h0 x) /\
h0 == h1 /\
v == Seq.index (sel h0 x) i)
= let s = !x in
Seq.index s i
let upd (#a:Type0) (x:array a) (i:nat) (v:a)
: HoareST unit
(fun h -> i < Seq.length (sel h x))
(fun h0 _ h1 ->
i < Seq.length (sel h0 x) /\
modifies (Set.singleton (addr_of x)) h0 h1 /\
sel h1 x == Seq.upd (sel h0 x) i v)
= let s = !x in
let s = Seq.upd s i v in
x := s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: HoareSTPolyBind.array a -> HoareSTPolyBind.HoareST Prims.nat | HoareSTPolyBind.HoareST | [] | [] | [
"HoareSTPolyBind.array",
"FStar.Seq.Base.length",
"Prims.nat",
"FStar.Seq.Base.seq",
"HoareSTPolyBind.op_Bang",
"FStar.Heap.trivial_preorder",
"FStar.Monotonic.Heap.heap",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.Heap.sel"
] | [] | false | true | false | false | false | let length (#a: Type0) (x: array a)
: HoareST nat (fun _ -> True) (fun h0 y h1 -> y == Seq.length (sel h0 x) /\ h0 == h1) =
| let s = !x in
Seq.length s | false |
HoareSTPolyBind.fst | HoareSTPolyBind.index | val index (#a: Type0) (x: array a) (i: nat)
: HoareST a
(fun h -> i < Seq.length (sel h x))
(fun h0 v h1 -> i < Seq.length (sel h0 x) /\ h0 == h1 /\ v == Seq.index (sel h0 x) i) | val index (#a: Type0) (x: array a) (i: nat)
: HoareST a
(fun h -> i < Seq.length (sel h x))
(fun h0 v h1 -> i < Seq.length (sel h0 x) /\ h0 == h1 /\ v == Seq.index (sel h0 x) i) | let index (#a:Type0) (x:array a) (i:nat)
: HoareST a
(fun h -> i < Seq.length (sel h x))
(fun h0 v h1 ->
i < Seq.length (sel h0 x) /\
h0 == h1 /\
v == Seq.index (sel h0 x) i)
= let s = !x in
Seq.index s i | {
"file_name": "examples/layeredeffects/HoareSTPolyBind.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 15,
"end_line": 280,
"start_col": 0,
"start_line": 272
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module HoareSTPolyBind
open FStar.Heap
open FStar.ST
module P = FStar.Preorder
module ST = FStar.ST
/// ST effect implemented as a layered effect over STATE
///
/// This module uses polymonadic binds to compose HoareST and PURE computations
///
/// See the `copy_aux` function below for some limitations of the polymonadic bind
#set-options "--max_fuel 0 --max_ifuel 0"
type pre_t = heap -> Type0
type post_t (a:Type) = heap -> a -> heap -> Type0
/// It has two indices: one for the precondition and one for the postcondition
///
/// Its encoding in STATE is as expected
type repr (a:Type) (pre:pre_t) (post:post_t a) : Type =
unit -> STATE a (fun p h -> pre h /\ (forall (x:a) (h1:heap). post h x h1 ==> p x h1))
let returnc (a:Type) (x:a)
: repr a (fun _ -> True) (fun h0 r h1 -> r == x /\ h0 == h1)
= fun _ -> x
/// bind bakes in the weakening of f's post to compose it with g's pre
let bind (a:Type) (b:Type)
(#pre_f:pre_t) (#post_f:post_t a) (#pre_g:a -> pre_t) (#post_g:a -> post_t b)
(f:repr a pre_f post_f) (g:(x:a -> repr b (pre_g x) (post_g x)))
: repr b
(fun h0 -> pre_f h0 /\ (forall (x:a) (h1:heap). post_f h0 x h1 ==> pre_g x h1))
(fun h0 y h2 -> exists (x:a) (h1:heap). pre_f h0 /\ post_f h0 x h1 /\ post_g x h1 y h2)
= fun _ ->
let x = f () in
g x ()
/// sub comp rule
let subcomp (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
: Pure (repr a pre_g post_g)
(requires
(forall (h:heap). pre_g h ==> pre_f h) /\
(forall (h0 h1:heap) (x:a). (pre_g h0 /\ post_f h0 x h1) ==> post_g h0 x h1))
(ensures fun _ -> True)
= f
let if_then_else (a:Type)
(#pre_f:pre_t) (#post_f:post_t a)
(#pre_g:pre_t) (#post_g:post_t a)
(f:repr a pre_f post_f)
(g:repr a pre_g post_g)
(p:bool)
: Type
= repr a
(fun h -> (p ==> pre_f h) /\ ((~ p) ==> pre_g h))
(fun h0 r h1 -> (p ==> post_f h0 r h1) /\ ((~ p) ==> post_g h0 r h1))
reflectable
effect {
HoareST (a:Type) (pre:pre_t) (post:post_t a)
with {repr;
return = returnc;
bind;
subcomp;
if_then_else}
}
/// Effect actions from FStar.ST
let recall (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST unit
(fun _ -> True)
(fun h0 _ h1 ->
h0 == h1 /\
h1 `Heap.contains` r)
= HoareST?.reflect (fun _ -> recall r)
let alloc (#a:Type) (#rel:P.preorder a) (init:a)
: HoareST (mref a rel)
(fun _ -> True)
(fun h0 r h1 ->
fresh r h0 h1 /\
modifies Set.empty h0 h1 /\
sel h1 r == init)
= HoareST?.reflect (fun _ -> alloc init)
let op_Bang (#a:Type) (#rel:P.preorder a) (r:mref a rel)
: HoareST a
(fun _ -> True)
(fun h0 x h1 ->
h0 == h1 /\
x == sel h1 r)
= HoareST?.reflect (fun _ -> read r)
let op_Colon_Equals (#a:Type) (#rel:P.preorder a) (r:mref a rel) (x:a)
: HoareST unit
(fun h -> rel (sel h r) x)
(fun h0 _ h1 ->
modifies (Set.singleton (addr_of r)) h0 h1 /\
equal_dom h0 h1 /\
sel h1 r == x)
= HoareST?.reflect (fun _ -> write r x)
let get ()
: HoareST heap
(fun _ -> True)
(fun h0 h h1 -> h0 == h1 /\ h == h1)
= HoareST?.reflect get
/// We don't define a traditional lift from PURE to HoareST
///
/// But rather we define two polymonadic binds
let bind_pure_hoarest (a:Type) (b:Type) (wp:pure_wp a) (req:a -> pre_t) (ens:a -> post_t b)
(f:unit -> PURE a wp) (g:(x:a -> repr b (req x) (ens x)))
: repr b
(fun h -> wp (fun x -> req x h))
(fun h0 r h1 -> exists x. (~ (wp (fun r -> r =!= x))) /\ ens x h0 r h1)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp;
fun _ ->
let x = f () in
g x ()
polymonadic_bind (PURE, HoareST) |> HoareST = bind_pure_hoarest
let bind_hoarest_pure (a:Type) (b:Type) (req:pre_t) (ens:post_t a) (wp:a -> pure_wp b)
(f:repr a req ens) (g:(x:a -> unit -> PURE b (wp x)))
: repr b
(fun h -> req h /\ (forall x h1. ens h x h1 ==> (wp x) (fun _ -> True)))
(fun h0 r h1 -> exists x. ens h0 x h1 /\ (~ ((wp x) (fun y -> y =!= r))))
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ ->
let x = f () in
(g x) ()
polymonadic_bind (HoareST, PURE) |> HoareST = bind_hoarest_pure
(*
// * PURE a wp <: HoareST a req ens
// *)
let subcomp_pure_hoarest (a:Type) (wp:pure_wp a) (req:pre_t) (ens:post_t a)
(f:unit -> PURE a wp)
: Pure (repr a req ens)
(requires
(forall h. req h ==> wp (fun _ -> True)) /\
(forall h0 r h1. (~ (wp (fun x -> x =!= r \/ h0 =!= h1))) ==> ens h0 r h1))
(ensures fun _ -> True)
= FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall ();
fun _ -> f ()
polymonadic_subcomp PURE <: HoareST = subcomp_pure_hoarest
let test_subcomp () : HoareST int (fun _ -> True) (fun _ r _ -> r == 0) = 0
assume val f_test_subcomp (n:int) : Pure int (n > 0) (fun r -> r > 0)
[@expect_failure]
let test_subcomp2 (n:int) : HoareST int (fun _ -> True) (fun _ _ _ -> True) = f_test_subcomp n
let test_subcomp3 (n:int) : HoareST int (fun _ -> n > 2) (fun _ _ _ -> True) = f_test_subcomp n
assume val f : x:int -> HoareST int (fun _ -> True) (fun _ r _ -> r == x + 1)
let test () : HoareST int (fun _ -> True) (fun _ r _ -> r == 1)
= f 0
open FStar.Monotonic.Pure
assume val g : int -> int -> PURE int (as_pure_wp (fun p -> forall x. p x))
let test2 () : HoareST int (fun _ -> True) (fun _ _ _ -> True)
= g 2 (f 0)
(*
// * In the polymonadic bind (PURE, HoareST) |> HoareST, the return type of
// * g is not allowed to depend on x, the return value of f
// *
// * So then what happens when a function f whose return type depends on its argument
// * is applied to a PURE term
// * NOTE: PURE and not Tot, since Tot will just be substituted,
// * without even invoking the bind
// *
// * When typechecking f e, the comp type is roughly
// * bind C_e C_ret_f, where C_ret_f is the comp type of f (below the arrow binder)
// * This is where bind comes in
// *)
assume type t_int (x:int) : Type0
assume val dep_f (x:int) : HoareST (t_int x) (fun _ -> True) (fun _ _ _ -> True)
assume val pure_g (_:unit) : PURE int (as_pure_wp (fun p -> forall (x:int). x >= 2 ==> p x))
let test_dep_f () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
dep_f (pure_g ())
(*
// * This works!
// *
// * The reason is that, before bind is called, the typechecker has already
// * substituted the pure term (pure_g ()) into the comp type of dep_f
// * (below the binder)
// *)
(*
// * But what happens when this is an explicit let binding?
// * as opposed to a function application
// *)
let test_dep_f2 () : HoareST (t_int (pure_g ())) (fun _ -> True) (fun _ _ _ -> True) =
let x = pure_g () in
dep_f x
(*
// * This also works because weakening the type using the annotation saves us!
// *)
module Seq = FStar.Seq
type array (a:Type0) = ref (Seq.seq a)
let op_At_Bar (#a:Type0) (s1:array a) (s2:array a)
: HoareST (array a)
(fun _ -> True)
(fun h0 r h1 ->
sel h1 r == Seq.append (sel h0 s1) (sel h0 s2) /\
modifies Set.empty h0 h1)
= let s1 = !s1 in
let s2 = !s2 in
alloc (Seq.append s1 s2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.ST.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Pure.fst.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "HoareSTPolyBind.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: HoareSTPolyBind.array a -> i: Prims.nat -> HoareSTPolyBind.HoareST a | HoareSTPolyBind.HoareST | [] | [] | [
"HoareSTPolyBind.array",
"Prims.nat",
"FStar.Seq.Base.index",
"FStar.Seq.Base.seq",
"HoareSTPolyBind.op_Bang",
"FStar.Heap.trivial_preorder",
"FStar.Monotonic.Heap.heap",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Monotonic.Heap.sel",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let index (#a: Type0) (x: array a) (i: nat)
: HoareST a
(fun h -> i < Seq.length (sel h x))
(fun h0 v h1 -> i < Seq.length (sel h0 x) /\ h0 == h1 /\ v == Seq.index (sel h0 x) i) =
| let s = !x in
Seq.index s i | false |
Pulse.Checker.Prover.Substs.fsti | Pulse.Checker.Prover.Substs.nt_subst_term | val nt_subst_term (t: term) (ss: nt_substs) : term | val nt_subst_term (t: term) (ss: nt_substs) : term | let nt_subst_term (t:term) (ss:nt_substs) : term =
L.fold_left (fun t elt -> subst_term t [elt]) t ss | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Substs.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 52,
"end_line": 84,
"start_col": 0,
"start_line": 83
} | (*
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.Checker.Prover.Substs
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing.Env
open Pulse.Typing
module L = FStar.List.Tot
module T = FStar.Tactics
module Env = Pulse.Typing.Env
val ss_t : Type0
val ln_ss_t (s:ss_t) : bool
val as_map (ss:ss_t) : Map.t var term
let dom (ss:ss_t) = Map.domain (as_map ss)
let contains (ss:ss_t) (x:var) = Map.contains (as_map ss) x
let sel (ss:ss_t) (x:var { contains ss x }) = Map.sel (as_map ss) x
val empty : ss_t
val push (ss:ss_t) (x:var { ~ (contains ss x) }) (t:term) : ss_t
val push_ss (ss1:ss_t) (ss2:ss_t { Set.disjoint (dom ss1) (dom ss2) }) : ss_t
val check_disjoint (ss1 ss2:ss_t) : b:bool { b ==> Set.disjoint (dom ss1) (dom ss2) }
val diff (ss1 ss2:ss_t) : ss:ss_t { Set.disjoint (dom ss) (dom ss2) }
val push_as_map (ss1 ss2:ss_t)
: Lemma (requires Set.disjoint (dom ss1) (dom ss2))
(ensures as_map (push_ss ss1 ss2) == Map.concat (as_map ss1) (as_map ss2))
[SMTPat (as_map (push_ss ss1 ss2))]
val ss_term (t:term) (ss:ss_t) : term
val ss_st_term (t:st_term) (ss:ss_t) : st_term
val ss_st_comp (s:st_comp) (ss:ss_t) : st_comp
val ss_comp (c:comp) (ss:ss_t) : comp
val ss_binder (b:binder) (ss:ss_t) : binder
val ss_env (g:env) (ss:ss_t)
: g':env { fstar_env g' == fstar_env g /\
Env.dom g' == Env.dom g }
val ss_st_comp_commutes (s:st_comp) (ss:ss_t)
: Lemma (ensures
ss_st_comp s ss ==
{ s with res = ss_term s.res ss;
pre = ss_term s.pre ss;
post = ss_term s.post ss; }) // no shifting required
[SMTPat (ss_st_comp s ss)]
val ss_comp_commutes (c:comp) (ss:ss_t)
: Lemma (ensures
(let r = ss_comp c ss in
(C_Tot? c ==> r == C_Tot (ss_term (comp_res c) ss)) /\
(C_ST? c ==> r == C_ST (ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STAtomic? c ==> r == C_STAtomic (ss_term (comp_inames c) ss)
(C_STAtomic?.obs c)
(ss_st_comp (st_comp_of_comp c) ss)) /\
(C_STGhost? c ==> r == C_STGhost (ss_st_comp (st_comp_of_comp c) ss))))
[SMTPat (ss_comp c ss)]
type nt_substs = l:list subst_elt { forall elt. L.memP elt l ==> NT? elt } | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Checker.Prover.Substs.fsti"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> ss: Pulse.Checker.Prover.Substs.nt_substs -> Pulse.Syntax.Base.term | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Checker.Prover.Substs.nt_substs",
"FStar.List.Tot.Base.fold_left",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.subst_term",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | true | false | let nt_subst_term (t: term) (ss: nt_substs) : term =
| L.fold_left (fun t elt -> subst_term t [elt]) t ss | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.