effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Pure | val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c)) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div a b = Mk (div (v a) (v b)) | val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
let div a b = | false | null | false | Mk (div (v a) (v b)) | {
"checked_file": "FStar.UInt32.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt32.fst"
} | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.UInt32.v",
"FStar.UInt32.Mk",
"FStar.UInt.div",
"FStar.UInt32.n"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt32
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b)) | false | false | FStar.UInt32.fst | {
"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"
} | null | val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c)) | [] | FStar.UInt32.div | {
"file_name": "ulib/FStar.UInt32.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt32.t -> b: FStar.UInt32.t{FStar.UInt32.v b <> 0} -> Prims.Pure FStar.UInt32.t | {
"end_col": 34,
"end_line": 60,
"start_col": 14,
"start_line": 60
} |
FStar.Pervasives.Lemma | val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_sub_msbs a b
= from_vec_propriety (to_vec (v a)) 1;
from_vec_propriety (to_vec (v b)) 1;
from_vec_propriety (to_vec (v (sub_mod a b))) 1 | val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
let lemma_sub_msbs a b = | false | null | true | from_vec_propriety (to_vec (v a)) 1;
from_vec_propriety (to_vec (v b)) 1;
from_vec_propriety (to_vec (v (sub_mod a b))) 1 | {
"checked_file": "FStar.UInt32.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt32.fst"
} | [
"lemma"
] | [
"FStar.UInt32.t",
"FStar.UInt.from_vec_propriety",
"FStar.UInt32.n",
"FStar.UInt.to_vec",
"FStar.UInt32.v",
"FStar.UInt32.sub_mod",
"Prims.unit"
] | [] | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt32
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b))
let logand x y = Mk (logand (v x) (v y))
let logxor x y = Mk (logxor (v x) (v y))
let logor x y = Mk (logor (v x) (v y))
let lognot x = Mk (lognot (v x))
let shift_right a s = Mk (shift_right (v a) (v s))
#push-options "--z3rlimit 80 --fuel 1" //AR: working around the interleaving semantics of pragmas
let shift_left a s = Mk (shift_left (v a) (v s)) | false | false | FStar.UInt32.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) | [] | FStar.UInt32.lemma_sub_msbs | {
"file_name": "ulib/FStar.UInt32.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt32.t -> b: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.msb (FStar.UInt32.v a) = FStar.UInt.msb (FStar.UInt32.v b) ==>
(FStar.UInt32.v a < FStar.UInt32.v b <==>
FStar.UInt.msb (FStar.UInt32.v (FStar.UInt32.sub_mod a b)))) | {
"end_col": 53,
"end_line": 81,
"start_col": 6,
"start_line": 79
} |
Prims.Tot | val sigma256_1_1: x:nat32 -> Tot (nat32) | [
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sigma256_1_1 x = v (_Sigma1 SHA2_256 (uint_to_t x)) | val sigma256_1_1: x:nat32 -> Tot (nat32)
let sigma256_1_1 x = | false | null | false | v (_Sigma1 SHA2_256 (uint_to_t x)) | {
"checked_file": "Vale.SHA2.Wrapper.fst.checked",
"dependencies": [
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA2.Wrapper.fst"
} | [
"total"
] | [
"Vale.Def.Words_s.nat32",
"FStar.UInt32.v",
"Spec.SHA2._Sigma1",
"Spec.Hash.Definitions.SHA2_256",
"FStar.UInt32.uint_to_t"
] | [] | module Vale.SHA2.Wrapper
open FStar.UInt32
open Spec.Agile.Hash
open Spec.SHA2
friend Lib.IntTypes
friend Spec.SHA2
let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x))
let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x))
let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x)) | false | true | Vale.SHA2.Wrapper.fst | {
"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"
} | null | val sigma256_1_1: x:nat32 -> Tot (nat32) | [] | Vale.SHA2.Wrapper.sigma256_1_1 | {
"file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32 | {
"end_col": 55,
"end_line": 15,
"start_col": 21,
"start_line": 15
} |
Prims.Tot | val sigma256_0_1: x:nat32 -> Tot (nat32) | [
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x)) | val sigma256_0_1: x:nat32 -> Tot (nat32)
let sigma256_0_1 x = | false | null | false | v (_sigma1 SHA2_256 (uint_to_t x)) | {
"checked_file": "Vale.SHA2.Wrapper.fst.checked",
"dependencies": [
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA2.Wrapper.fst"
} | [
"total"
] | [
"Vale.Def.Words_s.nat32",
"FStar.UInt32.v",
"Spec.SHA2._sigma1",
"Spec.Hash.Definitions.SHA2_256",
"FStar.UInt32.uint_to_t"
] | [] | module Vale.SHA2.Wrapper
open FStar.UInt32
open Spec.Agile.Hash
open Spec.SHA2
friend Lib.IntTypes
friend Spec.SHA2
let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x)) | false | true | Vale.SHA2.Wrapper.fst | {
"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"
} | null | val sigma256_0_1: x:nat32 -> Tot (nat32) | [] | Vale.SHA2.Wrapper.sigma256_0_1 | {
"file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32 | {
"end_col": 55,
"end_line": 11,
"start_col": 21,
"start_line": 11
} |
Prims.Tot | val sigma256_0_0: x:nat32 -> Tot (nat32) | [
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x)) | val sigma256_0_0: x:nat32 -> Tot (nat32)
let sigma256_0_0 x = | false | null | false | v (_sigma0 SHA2_256 (uint_to_t x)) | {
"checked_file": "Vale.SHA2.Wrapper.fst.checked",
"dependencies": [
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA2.Wrapper.fst"
} | [
"total"
] | [
"Vale.Def.Words_s.nat32",
"FStar.UInt32.v",
"Spec.SHA2._sigma0",
"Spec.Hash.Definitions.SHA2_256",
"FStar.UInt32.uint_to_t"
] | [] | module Vale.SHA2.Wrapper
open FStar.UInt32
open Spec.Agile.Hash
open Spec.SHA2
friend Lib.IntTypes
friend Spec.SHA2 | false | true | Vale.SHA2.Wrapper.fst | {
"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"
} | null | val sigma256_0_0: x:nat32 -> Tot (nat32) | [] | Vale.SHA2.Wrapper.sigma256_0_0 | {
"file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32 | {
"end_col": 55,
"end_line": 9,
"start_col": 21,
"start_line": 9
} |
Prims.Tot | val ch256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32) | [
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ch256 x y z = v (_Ch SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z)) | val ch256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32)
let ch256 x y z = | false | null | false | v (_Ch SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z)) | {
"checked_file": "Vale.SHA2.Wrapper.fst.checked",
"dependencies": [
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA2.Wrapper.fst"
} | [
"total"
] | [
"Vale.Def.Words_s.nat32",
"FStar.UInt32.v",
"Spec.SHA2._Ch",
"Spec.Hash.Definitions.SHA2_256",
"FStar.UInt32.uint_to_t"
] | [] | module Vale.SHA2.Wrapper
open FStar.UInt32
open Spec.Agile.Hash
open Spec.SHA2
friend Lib.IntTypes
friend Spec.SHA2
let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x))
let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x))
let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x))
let sigma256_1_1 x = v (_Sigma1 SHA2_256 (uint_to_t x)) | false | true | Vale.SHA2.Wrapper.fst | {
"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"
} | null | val ch256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32) | [] | Vale.SHA2.Wrapper.ch256 | {
"file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Def.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> z: Vale.Def.Words_s.nat32
-> Vale.Def.Words_s.nat32 | {
"end_col": 76,
"end_line": 17,
"start_col": 18,
"start_line": 17
} |
Prims.Tot | val sigma256_1_0: x:nat32 -> Tot (nat32) | [
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x)) | val sigma256_1_0: x:nat32 -> Tot (nat32)
let sigma256_1_0 x = | false | null | false | v (_Sigma0 SHA2_256 (uint_to_t x)) | {
"checked_file": "Vale.SHA2.Wrapper.fst.checked",
"dependencies": [
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA2.Wrapper.fst"
} | [
"total"
] | [
"Vale.Def.Words_s.nat32",
"FStar.UInt32.v",
"Spec.SHA2._Sigma0",
"Spec.Hash.Definitions.SHA2_256",
"FStar.UInt32.uint_to_t"
] | [] | module Vale.SHA2.Wrapper
open FStar.UInt32
open Spec.Agile.Hash
open Spec.SHA2
friend Lib.IntTypes
friend Spec.SHA2
let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x))
let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x)) | false | true | Vale.SHA2.Wrapper.fst | {
"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"
} | null | val sigma256_1_0: x:nat32 -> Tot (nat32) | [] | Vale.SHA2.Wrapper.sigma256_1_0 | {
"file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32 | {
"end_col": 55,
"end_line": 13,
"start_col": 21,
"start_line": 13
} |
Prims.Tot | val maj256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32) | [
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let maj256 x y z = v (_Maj SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z)) | val maj256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32)
let maj256 x y z = | false | null | false | v (_Maj SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z)) | {
"checked_file": "Vale.SHA2.Wrapper.fst.checked",
"dependencies": [
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA2.Wrapper.fst"
} | [
"total"
] | [
"Vale.Def.Words_s.nat32",
"FStar.UInt32.v",
"Spec.SHA2._Maj",
"Spec.Hash.Definitions.SHA2_256",
"FStar.UInt32.uint_to_t"
] | [] | module Vale.SHA2.Wrapper
open FStar.UInt32
open Spec.Agile.Hash
open Spec.SHA2
friend Lib.IntTypes
friend Spec.SHA2
let sigma256_0_0 x = v (_sigma0 SHA2_256 (uint_to_t x))
let sigma256_0_1 x = v (_sigma1 SHA2_256 (uint_to_t x))
let sigma256_1_0 x = v (_Sigma0 SHA2_256 (uint_to_t x))
let sigma256_1_1 x = v (_Sigma1 SHA2_256 (uint_to_t x))
let ch256 x y z = v (_Ch SHA2_256 (uint_to_t x) (uint_to_t y) (uint_to_t z)) | false | true | Vale.SHA2.Wrapper.fst | {
"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"
} | null | val maj256: x:nat32 -> y:nat32 -> z:nat32 -> Tot (nat32) | [] | Vale.SHA2.Wrapper.maj256 | {
"file_name": "vale/specs/crypto/Vale.SHA2.Wrapper.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Def.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> z: Vale.Def.Words_s.nat32
-> Vale.Def.Words_s.nat32 | {
"end_col": 78,
"end_line": 19,
"start_col": 19,
"start_line": 19
} |
Prims.Tot | val extract_blake2s_128:extract_st Blake2S | [
{
"abbrev": false,
"full_module": "Hacl.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let extract_blake2s_128: extract_st Blake2S =
mk_extract Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128 | val extract_blake2s_128:extract_st Blake2S
let extract_blake2s_128:extract_st Blake2S = | false | null | false | mk_extract Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128 | {
"checked_file": "Hacl.HKDF.Blake2s_128.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Hacl.HMAC.Blake2s_128.fst.checked",
"Hacl.HKDF.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HKDF.Blake2s_128.fst"
} | [
"total"
] | [
"Hacl.HKDF.mk_extract",
"Spec.Hash.Definitions.Blake2S",
"Hacl.HMAC.Blake2s_128.compute_blake2s_128"
] | [] | module Hacl.HKDF.Blake2s_128
open Spec.Hash.Definitions
open Hacl.HKDF
#set-options "--z3rlimit 20 --fuel 0 --ifuel 0"
[@@ Comment "Expand pseudorandom key to desired length.
@param okm Pointer to `len` bytes of memory where output keying material is written to.
@param prk Pointer to at least `HashLen` bytes of memory where pseudorandom key is read from. Usually, this points to the output from the extract step.
@param prklen Length of pseudorandom key.
@param info Pointer to `infolen` bytes of memory where context and application specific information is read from. Can be a zero-length string.
@param infolen Length of context and application specific information.
@param len Length of output keying material."]
let expand_blake2s_128: expand_st Blake2S =
mk_expand Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128
[@@ Comment "Extract a fixed-length pseudorandom key from input keying material.
@param prk Pointer to `HashLen` bytes of memory where pseudorandom key is written to.
@param salt Pointer to `saltlen` bytes of memory where salt value is read from.
@param saltlen Length of salt value.
@param ikm Pointer to `ikmlen` bytes of memory where input keying material is read from.
@param ikmlen Length of input keying material."] | false | true | Hacl.HKDF.Blake2s_128.fst | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val extract_blake2s_128:extract_st Blake2S | [] | Hacl.HKDF.Blake2s_128.extract_blake2s_128 | {
"file_name": "code/hkdf/Hacl.HKDF.Blake2s_128.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HKDF.extract_st Spec.Hash.Definitions.Blake2S | {
"end_col": 62,
"end_line": 27,
"start_col": 2,
"start_line": 27
} |
Prims.Tot | val expand_blake2s_128:expand_st Blake2S | [
{
"abbrev": false,
"full_module": "Hacl.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HKDF",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let expand_blake2s_128: expand_st Blake2S =
mk_expand Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128 | val expand_blake2s_128:expand_st Blake2S
let expand_blake2s_128:expand_st Blake2S = | false | null | false | mk_expand Blake2S Hacl.HMAC.Blake2s_128.compute_blake2s_128 | {
"checked_file": "Hacl.HKDF.Blake2s_128.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Hacl.HMAC.Blake2s_128.fst.checked",
"Hacl.HKDF.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HKDF.Blake2s_128.fst"
} | [
"total"
] | [
"Hacl.HKDF.mk_expand",
"Spec.Hash.Definitions.Blake2S",
"Hacl.HMAC.Blake2s_128.compute_blake2s_128"
] | [] | module Hacl.HKDF.Blake2s_128
open Spec.Hash.Definitions
open Hacl.HKDF
#set-options "--z3rlimit 20 --fuel 0 --ifuel 0"
[@@ Comment "Expand pseudorandom key to desired length.
@param okm Pointer to `len` bytes of memory where output keying material is written to.
@param prk Pointer to at least `HashLen` bytes of memory where pseudorandom key is read from. Usually, this points to the output from the extract step.
@param prklen Length of pseudorandom key.
@param info Pointer to `infolen` bytes of memory where context and application specific information is read from. Can be a zero-length string.
@param infolen Length of context and application specific information.
@param len Length of output keying material."] | false | true | Hacl.HKDF.Blake2s_128.fst | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val expand_blake2s_128:expand_st Blake2S | [] | Hacl.HKDF.Blake2s_128.expand_blake2s_128 | {
"file_name": "code/hkdf/Hacl.HKDF.Blake2s_128.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.HKDF.expand_st Spec.Hash.Definitions.Blake2S | {
"end_col": 61,
"end_line": 17,
"start_col": 2,
"start_line": 17
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let term_eq = FStar.Tactics.term_eq_old | let term_eq = | false | null | false | FStar.Tactics.term_eq_old | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Tactics.V1.Builtins.term_eq_old"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"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"
} | null | val term_eq : _: FStar.Reflection.Types.term -> _: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.bool | [] | FStar.InteractiveHelpers.PostProcess.term_eq | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Reflection.Types.term -> _: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 39,
"end_line": 12,
"start_col": 14,
"start_line": 12
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a) | let pred_explorer (a: Type) = | false | null | false | genv -> list (genv & term_view) -> option typ_or_comp -> term_view -> Tac (option a) | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result | false | true | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pred_explorer : a: Type -> Type0 | [] | FStar.InteractiveHelpers.PostProcess.pred_explorer | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: Type -> Type0 | {
"end_col": 16,
"end_line": 99,
"start_col": 2,
"start_line": 98
} |
|
FStar.Tactics.Effect.Tac | val is_focused_term : term_view -> Tac (option term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None | val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv = | true | null | false | match tv with
| Tv_Let recf attrs _ _ def body -> if is_focus_on_term def then Some body else None
| _ -> None | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Reflection.V1.Data.term_view",
"Prims.bool",
"Prims.list",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.PostProcess.is_focus_on_term"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_focused_term : term_view -> Tac (option term) | [] | FStar.InteractiveHelpers.PostProcess.is_focused_term | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | tv: FStar.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Reflection.Types.term) | {
"end_col": 13,
"end_line": 86,
"start_col": 2,
"start_line": 83
} |
FStar.Tactics.Effect.Tac | val pp_explore_print_goal : unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f () | val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () = | true | null | false | let f:explorer unit = fun _ _ _ _ _ -> ((), Continue) in
pp_explore true false f () | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.unit",
"FStar.InteractiveHelpers.PostProcess.pp_explore",
"FStar.InteractiveHelpers.ExploreTerm.explorer",
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.Types.ctrl_flag",
"FStar.Tactics.Types.Continue"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging. | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pp_explore_print_goal : unit -> Tac unit | [] | FStar.InteractiveHelpers.PostProcess.pp_explore_print_goal | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 28,
"end_line": 61,
"start_col": 30,
"start_line": 57
} |
Prims.Tot | val _is_focused_term_explorer : pred_explorer term | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv | val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv = | false | null | false | is_focused_term tv | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.InteractiveHelpers.PostProcess.is_focused_term",
"FStar.Reflection.Types.term"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term | false | true | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val _is_focused_term_explorer : pred_explorer term | [] | FStar.InteractiveHelpers.PostProcess._is_focused_term_explorer | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | FStar.InteractiveHelpers.PostProcess.pred_explorer FStar.Reflection.Types.term | {
"end_col": 20,
"end_line": 124,
"start_col": 2,
"start_line": 124
} |
FStar.Tactics.Effect.Tac | val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term)) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t | val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t = | true | null | false | find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.PostProcess.find_predicated_term",
"FStar.InteractiveHelpers.PostProcess._is_focused_term_explorer",
"FStar.InteractiveHelpers.PostProcess.exploration_result"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term)) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term)) | [] | FStar.InteractiveHelpers.PostProcess.find_focused_term | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
dfs: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
pl: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Reflection.V1.Data.term_view) ->
opt_c: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp ->
t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Reflection.Types.term
)) | {
"end_col": 76,
"end_line": 129,
"start_col": 2,
"start_line": 129
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let end_proof () =
tadmit_t (`()) | let end_proof () = | true | null | false | tadmit_t (`()) | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V1.Builtins.tadmit_t"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val end_proof : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | [] | FStar.InteractiveHelpers.PostProcess.end_proof | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 16,
"end_line": 26,
"start_col": 2,
"start_line": 26
} |
|
FStar.Tactics.Effect.Tac | val unsquash_equality (t: term) : Tac (option (term & term)) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end | val unsquash_equality (t: term) : Tac (option (term & term))
let unsquash_equality (t: term) : Tac (option (term & term)) = | true | null | false | match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Formula.formula",
"FStar.Pervasives.Native.None",
"FStar.Reflection.V1.Formula.term_as_formula"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`()) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val unsquash_equality (t: term) : Tac (option (term & term)) | [] | FStar.InteractiveHelpers.PostProcess.unsquash_equality | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (FStar.Reflection.Types.term * FStar.Reflection.Types.term)) | {
"end_col": 13,
"end_line": 31,
"start_col": 8,
"start_line": 29
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_exploration_result = Mkexploration_result | let mk_exploration_result = | false | null | false | Mkexploration_result | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.PostProcess.Mkexploration_result",
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.InteractiveHelpers.PostProcess.exploration_result"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
} | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_exploration_result : ge: FStar.InteractiveHelpers.Base.genv ->
parents: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Reflection.V1.Data.term_view) ->
tgt_comp: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp ->
res: _
-> FStar.InteractiveHelpers.PostProcess.exploration_result _ | [] | FStar.InteractiveHelpers.PostProcess.mk_exploration_result | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
ge: FStar.InteractiveHelpers.Base.genv ->
parents: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Reflection.V1.Data.term_view) ->
tgt_comp: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp ->
res: _
-> FStar.InteractiveHelpers.PostProcess.exploration_result _ | {
"end_col": 48,
"end_line": 95,
"start_col": 28,
"start_line": 95
} |
|
FStar.Tactics.Effect.Tac | val is_focus_on_term : term -> Tac bool | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_focus_on_term t = is_fvar t (`%focus_on_term) | val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = | true | null | false | is_fvar t (`%focus_on_term) | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Derived.is_fvar",
"Prims.bool"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_focus_on_term : term -> Tac bool | [] | FStar.InteractiveHelpers.PostProcess.is_focus_on_term | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool | {
"end_col": 52,
"end_line": 66,
"start_col": 25,
"start_line": 66
} |
FStar.Tactics.Effect.Tac | val remove_b2t : term -> Tac term | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t | val remove_b2t : term -> Tac term
let remove_b2t (t: term) : Tac term = | true | null | false | match inspect t with
| Tv_App hd (a, Q_Explicit) ->
(match inspect hd with
| Tv_FVar fv -> if fv_eq_name fv b2t_qn then a else t
| _ -> t)
| _ -> t | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.fv",
"FStar.InteractiveHelpers.Base.fv_eq_name",
"FStar.Reflection.Const.b2t_qn",
"Prims.bool",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val remove_b2t : term -> Tac term | [] | FStar.InteractiveHelpers.PostProcess.remove_b2t | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term | {
"end_col": 10,
"end_line": 275,
"start_col": 2,
"start_line": 268
} |
FStar.Tactics.Effect.Tac | val pp_split_assert_conjs : bool -> unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err | val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () = | true | null | false | try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with
| MetaAnalysis msg ->
printout_failure msg;
end_proof ()
| err -> raise err | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"Prims.unit",
"FStar.Tactics.V1.Derived.try_with",
"FStar.InteractiveHelpers.PostProcess.end_proof",
"FStar.InteractiveHelpers.PostProcess.split_assert_conjs",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.PostProcess.find_focused_assert_in_current_goal",
"Prims.exn",
"Prims.string",
"FStar.InteractiveHelpers.Output.printout_failure",
"FStar.Tactics.Effect.raise"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pp_split_assert_conjs : bool -> unit -> Tac unit | [] | FStar.InteractiveHelpers.PostProcess.pp_split_assert_conjs | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 89,
"end_line": 353,
"start_col": 2,
"start_line": 348
} |
FStar.Tactics.Effect.Tac | val split_conjunctions_under_match : bool -> term -> Tac (list term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t] | val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t = | true | null | false | let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [pat, br] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ -> [t] | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.match_returns_ascription",
"FStar.Reflection.V1.Data.pattern",
"FStar.Tactics.Util.map",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_Match",
"Prims.Cons",
"FStar.Reflection.V1.Data.branch",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"Prims.list",
"FStar.InteractiveHelpers.PostProcess.split_conjunctions",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.term_construct",
"FStar.InteractiveHelpers.PostProcess.remove_b2t"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val split_conjunctions_under_match : bool -> term -> Tac (list term) | [] | FStar.InteractiveHelpers.PostProcess.split_conjunctions_under_match | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac (Prims.list FStar.Reflection.Types.term) | {
"end_col": 7,
"end_line": 324,
"start_col": 42,
"start_line": 315
} |
FStar.Tactics.Effect.Tac | val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a)) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t) | val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t = | true | null | false | fst (explore_term dbg
dfs
#(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None
ge
pl
opt_c
t) | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.InteractiveHelpers.PostProcess.pred_explorer",
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.Reflection.Types.term",
"FStar.Pervasives.Native.fst",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Tactics.Types.ctrl_flag",
"FStar.InteractiveHelpers.ExploreTerm.explore_term",
"FStar.InteractiveHelpers.PostProcess.find_predicated_term_explorer",
"FStar.Pervasives.Native.None"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a)) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a)) | [] | FStar.InteractiveHelpers.PostProcess.find_predicated_term | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
pred: FStar.InteractiveHelpers.PostProcess.pred_explorer a ->
dbg: Prims.bool ->
dfs: Prims.bool ->
ge: FStar.InteractiveHelpers.Base.genv ->
pl: Prims.list (FStar.InteractiveHelpers.Base.genv * FStar.Reflection.V1.Data.term_view) ->
opt_c: FStar.Pervasives.Native.option FStar.InteractiveHelpers.ExploreTerm.typ_or_comp ->
t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (FStar.InteractiveHelpers.PostProcess.exploration_result a)) | {
"end_col": 39,
"end_line": 120,
"start_col": 2,
"start_line": 118
} |
FStar.Tactics.Effect.Tac | val split_assert_conjs : bool -> exploration_result term -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts | val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res = | true | null | false | let ge0 = res.ge in
let t = norm_term_env ge0.env simpl_norm_steps res.res in
let conjs = split_conjunctions t in
let conjs = if List.length conjs = 1 then split_conjunctions_under_match dbg t else conjs in
let asserts = mk_assertions conjs [] in
printout_success ge0 asserts | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Output.printout_success",
"Prims.unit",
"FStar.InteractiveHelpers.Propositions.assertions",
"FStar.InteractiveHelpers.Propositions.mk_assertions",
"Prims.Nil",
"FStar.InteractiveHelpers.Propositions.proposition",
"Prims.list",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"FStar.InteractiveHelpers.PostProcess.split_conjunctions_under_match",
"FStar.InteractiveHelpers.PostProcess.split_conjunctions",
"FStar.Tactics.V1.Builtins.norm_term_env",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"FStar.InteractiveHelpers.Propositions.simpl_norm_steps",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res",
"FStar.InteractiveHelpers.Base.genv",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t] | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val split_assert_conjs : bool -> exploration_result term -> Tac unit | [] | FStar.InteractiveHelpers.PostProcess.split_assert_conjs | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
res: FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 30,
"end_line": 343,
"start_col": 32,
"start_line": 327
} |
FStar.Tactics.Effect.Tac | val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err | val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () = | true | null | false | try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with
| MetaAnalysis msg ->
printout_failure msg;
end_proof ()
| err -> raise err | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"Prims.unit",
"FStar.Tactics.V1.Derived.try_with",
"FStar.InteractiveHelpers.PostProcess.end_proof",
"FStar.InteractiveHelpers.PostProcess.analyze_effectful_term",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.PostProcess.find_focused_term_in_current_goal",
"Prims.exn",
"Prims.string",
"FStar.InteractiveHelpers.Output.printout_failure",
"FStar.Tactics.Effect.raise"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit | [] | FStar.InteractiveHelpers.PostProcess.pp_analyze_effectful_term | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> with_gpre: Prims.bool -> with_gpost: Prims.bool -> _: Prims.unit
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 89,
"end_line": 253,
"start_col": 2,
"start_line": 248
} |
FStar.Tactics.Effect.Tac | val pp_unfold_in_assert_or_assume : bool -> unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pp_unfold_in_assert_or_assume dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
unfold_in_assert_or_assume dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err | val pp_unfold_in_assert_or_assume : bool -> unit -> Tac unit
let pp_unfold_in_assert_or_assume dbg () = | true | null | false | try
let res = find_focused_assert_in_current_goal dbg in
unfold_in_assert_or_assume dbg res;
end_proof ()
with
| MetaAnalysis msg ->
printout_failure msg;
end_proof ()
| err -> raise err | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"Prims.unit",
"FStar.Tactics.V1.Derived.try_with",
"FStar.InteractiveHelpers.PostProcess.end_proof",
"FStar.InteractiveHelpers.PostProcess.unfold_in_assert_or_assume",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.PostProcess.find_focused_assert_in_current_goal",
"Prims.exn",
"Prims.string",
"FStar.InteractiveHelpers.Output.printout_failure",
"FStar.Tactics.Effect.raise"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts
/// Look for an equality in a postcondition which can be used for rewriting.
val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term)
let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
(* Compute the post-condition *)
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty))
tinfo einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
(* Look for an equality in the post *)
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
(* If we found something, we return the updated environment,
* otherwise we can return the original one *)
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm
/// Given a list of parent terms (as generated by ``explore_term``), look for an
/// equality given by a post-condition which can be used to replace a term.
val find_context_equality :
dbg:bool
-> ge0:genv
-> tm:term
-> parents:list term_view
-> children:list term_view
-> Tac (genv & option term)
/// Auxiliary function which actually performs the search
let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv)
(parents children : list term_view) :
Tac (genv & option term) =
match parents with
| [] -> ge0, None
| tv :: parents' ->
print_dbg dbg ("[> find_context_equality:\n" ^
"- term : " ^ term_to_string tm ^ "\n" ^
"- parent: " ^ term_to_string tv);
(* We only consider let-bindings *)
match tv with
| Tv_Let _ _ bv' ty def _ ->
print_dbg dbg "Is Tv_Let";
let tm_info = compute_eterm_info dbg ge0.env def in
let einfo = tm_info.einfo in
(* If the searched term is a bv and the current let is the one which
* introduces it:
* - if the term is effectful, use it
* - otherwise, try to use its postcondition. If we don't find any
* equalities, some there *)
let let_bv_is_tm =
match opt_bv with
| Some tm_bv -> bv_eq tm_bv bv'
| None -> false
in
if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def
else
let ret_value = pack (Tv_Var bv') in
begin match find_equality_from_post dbg ge0 tm bv' ty ret_value
einfo parents children with
| ge1, Some p -> ge1, Some p
| _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
end
| _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
let find_context_equality dbg ge0 tm parents children =
let opt_bv =
match inspect tm with
| Tv_Var bv -> Some bv
| _ -> None
in
find_context_equality_aux dbg ge0 tm opt_bv parents children
/// Replace a subterm by another term
val replace_term_in : bool -> term -> term -> term -> Tac term
let rec replace_term_in dbg from_term to_term tm =
if term_eq from_term tm then to_term else
match inspect tm with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm
| Tv_App hd (a, qual) ->
let a' = replace_term_in dbg from_term to_term a in
let hd' = replace_term_in dbg from_term to_term hd in
pack (Tv_App hd' (a', qual))
| Tv_Abs br body ->
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Abs br body')
| Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *)
| Tv_Type _ -> tm
| Tv_Refine bv sort ref ->
let sort' = replace_term_in dbg from_term to_term sort in
let ref' = replace_term_in dbg from_term to_term ref in
pack (Tv_Refine bv sort' ref')
| Tv_Const _ -> tm
| Tv_Uvar _ _ -> tm
| Tv_Let recf attrs bv ty def body ->
(* GM 2023-04-27: leaving ty untouched, old code did not
descend into sort. *)
let def' = replace_term_in dbg from_term to_term def in
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Let recf attrs bv ty def' body')
| Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation
(* Auxiliary function to explore the branches *)
let explore_branch (br : branch) : Tac branch =
(* Only explore the branch body *)
let pat, body = br in
let body' = replace_term_in dbg from_term to_term body in
(pat, body')
in
let scrutinee' = replace_term_in dbg from_term to_term scrutinee in
let branches' = map explore_branch branches in
pack (Tv_Match scrutinee' ret_opt branches')
| Tv_AscribedT e ty tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
let ty' = replace_term_in dbg from_term to_term ty in
pack (Tv_AscribedT e' ty' tac use_eq)
| Tv_AscribedC e c tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
pack (Tv_AscribedC e' c tac use_eq)
| _ ->
(* Unknown *)
tm
val strip_implicit_parameters : term -> Tac term
let rec strip_implicit_parameters tm =
match inspect tm with
| Tv_App hd (a,qualif) ->
if Q_Implicit? qualif then strip_implicit_parameters hd else tm
| _ -> tm
val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit
let unfold_in_assert_or_assume dbg ares =
print_dbg dbg ("[> unfold_in_assert_or_assume:\n" ^ term_to_string ares.res);
(* Find the focused term inside the assert, and on which side of the
* equality if the assert is an equality *)
let find_focused_in_term t =
find_focused_term dbg false ares.ge ares.parents ares.tgt_comp t
in
let find_in_whole_term () : Tac _ =
match find_focused_in_term ares.res with
| Some res ->
ares.res, res, (fun x -> x <: Tac term), true
| None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
in
(* - subterm: the subterm of the assertion in which we found the focused term
* (if an equality, left or right operand, otherwise whole assertion)
* - unf_res: the result of the exploration for the focused term inside the
* assertion, which gives the term to unfold
* - rebuild: a Tot function which, given a term, rebuilds the equality by
* replacing the above subterm with the given term
* - insert_before: whether to insert the new assertion before or after the
* current assertion in the user file *)
let subterm, unf_res, (rebuild : term -> Tac term), insert_before =
let _ = print_dbg dbg ("Assertion: " ^ term_to_string ares.res) in
match is_eq dbg ares.res with
| Some (kd, l, r) ->
print_dbg dbg "The assertion is an equality";
begin match find_focused_in_term l with
| Some res ->
print_dbg dbg ("Found focused term in left operand:" ^
"\n- left : " ^ term_to_string l ^
"\n- right : " ^ term_to_string r ^
"\n- focused: " ^ term_to_string res.res);
let rebuild t : Tac term = mk_eq kd t r in
l, res, rebuild, true
| None ->
begin match find_focused_in_term r with
| Some res ->
print_dbg dbg ("Found focused term in right operand:" ^
"\n- left : " ^ term_to_string l ^
"\n- right : " ^ term_to_string r ^
"\n- focused: " ^ term_to_string res.res);
let rebuild (t : term) : Tac term = mk_eq kd l t in
r, res, rebuild, false
| None ->
mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
end
end
| None ->
print_dbg dbg "The assertion is not an equality";
find_in_whole_term ()
in
print_dbg dbg ("Found subterm in assertion/assumption:\n" ^
"- subterm: " ^ term_to_string subterm ^ "\n" ^
"- focused term: " ^ term_to_string unf_res.res);
(* Unfold the term *)
let res_view = inspect unf_res.res in
let ge1, opt_unf_tm =
match res_view with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier: " ^ fv_to_string fv);
(* The easy case: just use the normalizer *)
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ares.ge.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ares.ge, Some subterm'
| _ ->
(* Look for an equality given by a previous post-condition. In the case
* the term is a bv, we can also use the let-binding which introduces it,
* if it is pure. *)
let parents = List.Tot.map snd ares.parents in
let opt_bvty : option (bv & typ) =
match res_view with
| Tv_Var bv ->
print_dbg dbg ("The focused term is a local variable: " ^ bv_to_string bv);
(* Check that the binder was not introduced by an abstraction inside the assertion *)
if not (Some? (genv_get ares.ge bv)) then
mfail "unfold_in_assert_or_assume: can't unfold a variable locally introduced in an assertion";
Some (bv, pack_ln Tv_Unknown) // FIXME
| _ ->
print_dbg dbg ("The focused term is an arbitrary term: " ^ term_to_string unf_res.res);
None
in
let ge1, eq_tm = find_context_equality dbg ares.ge unf_res.res parents [] in
(* Check if we found an equality *)
let opt_eq_tm =
match eq_tm with
| Some eq_tm -> Some eq_tm
| _ -> None
in
(* Apply it *)
let subterm' =
match opt_bvty, opt_eq_tm with
| Some bvty, Some eq_tm -> Some (apply_subst ge1.env subterm [(bvty, eq_tm)])
| None, Some eq_tm -> Some (replace_term_in dbg unf_res.res eq_tm subterm)
| _ -> None
in
ge1, subterm'
in
(* If we couldn't unfold the term, check if it is a top-level identifier with
* implicit parameters (it may happen that the user calls the command on a
* top-level identifier which has implicit parameters without providing
* those parameters, in which case the focused term is the identifier applied
* to those implicits inferred by F*, and thus an app and not an fvar).
* Note that so far we have no way to check if the implicit parameters have
* been explicitly provided by the user or not, which is why we can't do better
* than greedy tests.*)
let ge2, unf_tm =
match opt_unf_tm with
| Some unf_tm -> ge1, unf_tm
| None ->
begin match inspect (strip_implicit_parameters unf_res.res) with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier with implicit parameters: "
^ fv_to_string fv);
(* The easy case: just use the normalizer *)
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ge1.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ge1, subterm'
| _ ->
mfail ("unfold_in_assert_or_assume: " ^
"couldn't find equalities with which to rewrite: " ^
term_to_string unf_res.res)
end
in
(* Create the assertions to output *)
let final_assert = rebuild unf_tm in
let final_assert = prettify_term dbg final_assert in
print_dbg dbg ("-> Final assertion:\n" ^ term_to_string final_assert);
let asserts =
if insert_before then mk_assertions [final_assert] [] else mk_assertions [] [final_assert]
in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 None asserts in
(* Output *)
printout_success ge3 asserts
[@plugin]
val pp_unfold_in_assert_or_assume : bool -> unit -> Tac unit | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pp_unfold_in_assert_or_assume : bool -> unit -> Tac unit | [] | FStar.InteractiveHelpers.PostProcess.pp_unfold_in_assert_or_assume | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 89,
"end_line": 747,
"start_col": 2,
"start_line": 742
} |
FStar.Tactics.Effect.Tac | val find_subequality : bool -> term -> term -> Tac (option term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts | val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p = | true | null | false | print_dbg dbg
("[> find_subequality:" ^ "\n- ter : " ^ term_to_string tm ^ "\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.term",
"FStar.Tactics.Util.tryPick",
"FStar.InteractiveHelpers.PostProcess.is_equality_for_term",
"FStar.Pervasives.Native.option",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.list_to_string",
"FStar.Tactics.V1.Builtins.term_to_string",
"Prims.list",
"FStar.InteractiveHelpers.PostProcess.split_conjunctions"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_subequality : bool -> term -> term -> Tac (option term) | [] | FStar.InteractiveHelpers.PostProcess.find_subequality | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> tm: FStar.Reflection.Types.term -> p: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Reflection.Types.term) | {
"end_col": 49,
"end_line": 464,
"start_col": 2,
"start_line": 459
} |
FStar.Tactics.Effect.Tac | val strip_implicit_parameters : term -> Tac term | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec strip_implicit_parameters tm =
match inspect tm with
| Tv_App hd (a,qualif) ->
if Q_Implicit? qualif then strip_implicit_parameters hd else tm
| _ -> tm | val strip_implicit_parameters : term -> Tac term
let rec strip_implicit_parameters tm = | true | null | false | match inspect tm with
| Tv_App hd (a, qualif) -> if Q_Implicit? qualif then strip_implicit_parameters hd else tm
| _ -> tm | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Data.uu___is_Q_Implicit",
"FStar.InteractiveHelpers.PostProcess.strip_implicit_parameters",
"Prims.bool",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts
/// Look for an equality in a postcondition which can be used for rewriting.
val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term)
let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
(* Compute the post-condition *)
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty))
tinfo einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
(* Look for an equality in the post *)
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
(* If we found something, we return the updated environment,
* otherwise we can return the original one *)
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm
/// Given a list of parent terms (as generated by ``explore_term``), look for an
/// equality given by a post-condition which can be used to replace a term.
val find_context_equality :
dbg:bool
-> ge0:genv
-> tm:term
-> parents:list term_view
-> children:list term_view
-> Tac (genv & option term)
/// Auxiliary function which actually performs the search
let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv)
(parents children : list term_view) :
Tac (genv & option term) =
match parents with
| [] -> ge0, None
| tv :: parents' ->
print_dbg dbg ("[> find_context_equality:\n" ^
"- term : " ^ term_to_string tm ^ "\n" ^
"- parent: " ^ term_to_string tv);
(* We only consider let-bindings *)
match tv with
| Tv_Let _ _ bv' ty def _ ->
print_dbg dbg "Is Tv_Let";
let tm_info = compute_eterm_info dbg ge0.env def in
let einfo = tm_info.einfo in
(* If the searched term is a bv and the current let is the one which
* introduces it:
* - if the term is effectful, use it
* - otherwise, try to use its postcondition. If we don't find any
* equalities, some there *)
let let_bv_is_tm =
match opt_bv with
| Some tm_bv -> bv_eq tm_bv bv'
| None -> false
in
if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def
else
let ret_value = pack (Tv_Var bv') in
begin match find_equality_from_post dbg ge0 tm bv' ty ret_value
einfo parents children with
| ge1, Some p -> ge1, Some p
| _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
end
| _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
let find_context_equality dbg ge0 tm parents children =
let opt_bv =
match inspect tm with
| Tv_Var bv -> Some bv
| _ -> None
in
find_context_equality_aux dbg ge0 tm opt_bv parents children
/// Replace a subterm by another term
val replace_term_in : bool -> term -> term -> term -> Tac term
let rec replace_term_in dbg from_term to_term tm =
if term_eq from_term tm then to_term else
match inspect tm with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm
| Tv_App hd (a, qual) ->
let a' = replace_term_in dbg from_term to_term a in
let hd' = replace_term_in dbg from_term to_term hd in
pack (Tv_App hd' (a', qual))
| Tv_Abs br body ->
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Abs br body')
| Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *)
| Tv_Type _ -> tm
| Tv_Refine bv sort ref ->
let sort' = replace_term_in dbg from_term to_term sort in
let ref' = replace_term_in dbg from_term to_term ref in
pack (Tv_Refine bv sort' ref')
| Tv_Const _ -> tm
| Tv_Uvar _ _ -> tm
| Tv_Let recf attrs bv ty def body ->
(* GM 2023-04-27: leaving ty untouched, old code did not
descend into sort. *)
let def' = replace_term_in dbg from_term to_term def in
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Let recf attrs bv ty def' body')
| Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation
(* Auxiliary function to explore the branches *)
let explore_branch (br : branch) : Tac branch =
(* Only explore the branch body *)
let pat, body = br in
let body' = replace_term_in dbg from_term to_term body in
(pat, body')
in
let scrutinee' = replace_term_in dbg from_term to_term scrutinee in
let branches' = map explore_branch branches in
pack (Tv_Match scrutinee' ret_opt branches')
| Tv_AscribedT e ty tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
let ty' = replace_term_in dbg from_term to_term ty in
pack (Tv_AscribedT e' ty' tac use_eq)
| Tv_AscribedC e c tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
pack (Tv_AscribedC e' c tac use_eq)
| _ ->
(* Unknown *)
tm
val strip_implicit_parameters : term -> Tac term | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val strip_implicit_parameters : term -> Tac term | [
"recursion"
] | FStar.InteractiveHelpers.PostProcess.strip_implicit_parameters | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | tm: FStar.Reflection.Types.term -> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term | {
"end_col": 11,
"end_line": 599,
"start_col": 2,
"start_line": 596
} |
FStar.Tactics.Effect.Tac | val pp_explore (dbg dfs: bool) (#a: Type0) (f: explorer a) (x: a) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end | val pp_explore (dbg dfs: bool) (#a: Type0) (f: explorer a) (x: a) : Tac unit
let pp_explore (dbg dfs: bool) (#a: Type0) (f: explorer a) (x: a) : Tac unit = | true | null | false | let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality" | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.ExploreTerm.explorer",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.PostProcess.end_proof",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.Types.ctrl_flag",
"FStar.InteractiveHelpers.ExploreTerm.explore_term",
"Prims.Nil",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Reflection.V1.Data.term_view",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.Base.mk_genv",
"FStar.Reflection.Types.bv",
"FStar.Pervasives.Native.tuple3",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.InteractiveHelpers.ExploreTerm.uu___is_TC_Comp",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.InteractiveHelpers.ExploreTerm.safe_typ_or_comp",
"FStar.InteractiveHelpers.Base.mfail",
"FStar.InteractiveHelpers.PostProcess.unsquash_equality",
"FStar.Reflection.Types.env",
"FStar.Tactics.V1.Derived.cur_env",
"FStar.Tactics.V1.Derived.cur_goal"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"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": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pp_explore (dbg dfs: bool) (#a: Type0) (f: explorer a) (x: a) : Tac unit | [] | FStar.InteractiveHelpers.PostProcess.pp_explore | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> dfs: Prims.bool -> f: FStar.InteractiveHelpers.ExploreTerm.explorer a -> x: a
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 5,
"end_line": 51,
"start_col": 12,
"start_line": 39
} |
FStar.Tactics.Effect.Tac | val is_equality_for_term : bool -> term -> term -> Tac (option term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None | val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p = | true | null | false | print_dbg dbg
("[> is_equality_for_term:" ^ "\n- term: " ^ term_to_string tm ^ "\n- prop: " ^ term_to_string p);
let check_eq: term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' ->
match inspect tm' with
| Tv_Var bv' -> bv_eq bv bv'
| _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind
then
(print_dbg dbg "Ignoring heterogeneous equality";
None)
else if check_eq l then Some r else if check_eq r then Some l else None
| _ ->
print_dbg dbg "Term is not eq";
None | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.PostProcess.eq_kind",
"FStar.InteractiveHelpers.PostProcess.uu___is_Eq_Hetero",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.Pervasives.Native.Some",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.PostProcess.is_eq",
"FStar.Reflection.Types.bv",
"FStar.InteractiveHelpers.Base.bv_eq",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect",
"FStar.InteractiveHelpers.PostProcess.term_eq"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_equality_for_term : bool -> term -> term -> Tac (option term) | [] | FStar.InteractiveHelpers.PostProcess.is_equality_for_term | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> tm: FStar.Reflection.Types.term -> p: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Reflection.Types.term) | {
"end_col": 8,
"end_line": 455,
"start_col": 2,
"start_line": 429
} |
FStar.Tactics.Effect.Tac | val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None | val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t = | true | null | false | let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
(match params with
| [a, Q_Implicit ; x, Q_Explicit ; y, Q_Explicit] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"]
then Some ((Eq_Dec a), x, y)
else
if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"]
then Some ((Eq_Undec a), x, y)
else None
| [a, Q_Implicit ; b, Q_Implicit ; x, Q_Explicit ; y, Q_Explicit] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then Some ((Eq_Hetero a b), x, y) else None
| _ -> None)
| _ -> None | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"FStar.Reflection.Types.fv",
"FStar.Reflection.V1.Derived.is_any_fvar",
"Prims.Cons",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.PostProcess.eq_kind",
"FStar.Pervasives.Native.Mktuple3",
"FStar.InteractiveHelpers.PostProcess.Eq_Dec",
"FStar.InteractiveHelpers.PostProcess.Eq_Undec",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.Reflection.V1.Derived.is_fvar",
"FStar.InteractiveHelpers.PostProcess.Eq_Hetero",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.list_to_string",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Tactics.V1.SyntaxHelpers.collect_app",
"FStar.InteractiveHelpers.PostProcess.remove_b2t"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula`` | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_eq : bool -> term -> Tac (option (eq_kind & term & term)) | [] | FStar.InteractiveHelpers.PostProcess.is_eq | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option ((FStar.InteractiveHelpers.PostProcess.eq_kind *
FStar.Reflection.Types.term) *
FStar.Reflection.Types.term)) | {
"end_col": 13,
"end_line": 393,
"start_col": 17,
"start_line": 372
} |
FStar.Tactics.Effect.Tac | val replace_term_in : bool -> term -> term -> term -> Tac term | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec replace_term_in dbg from_term to_term tm =
if term_eq from_term tm then to_term else
match inspect tm with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm
| Tv_App hd (a, qual) ->
let a' = replace_term_in dbg from_term to_term a in
let hd' = replace_term_in dbg from_term to_term hd in
pack (Tv_App hd' (a', qual))
| Tv_Abs br body ->
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Abs br body')
| Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *)
| Tv_Type _ -> tm
| Tv_Refine bv sort ref ->
let sort' = replace_term_in dbg from_term to_term sort in
let ref' = replace_term_in dbg from_term to_term ref in
pack (Tv_Refine bv sort' ref')
| Tv_Const _ -> tm
| Tv_Uvar _ _ -> tm
| Tv_Let recf attrs bv ty def body ->
(* GM 2023-04-27: leaving ty untouched, old code did not
descend into sort. *)
let def' = replace_term_in dbg from_term to_term def in
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Let recf attrs bv ty def' body')
| Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation
(* Auxiliary function to explore the branches *)
let explore_branch (br : branch) : Tac branch =
(* Only explore the branch body *)
let pat, body = br in
let body' = replace_term_in dbg from_term to_term body in
(pat, body')
in
let scrutinee' = replace_term_in dbg from_term to_term scrutinee in
let branches' = map explore_branch branches in
pack (Tv_Match scrutinee' ret_opt branches')
| Tv_AscribedT e ty tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
let ty' = replace_term_in dbg from_term to_term ty in
pack (Tv_AscribedT e' ty' tac use_eq)
| Tv_AscribedC e c tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
pack (Tv_AscribedC e' c tac use_eq)
| _ ->
(* Unknown *)
tm | val replace_term_in : bool -> term -> term -> term -> Tac term
let rec replace_term_in dbg from_term to_term tm = | true | null | false | if term_eq from_term tm
then to_term
else
match inspect tm with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm
| Tv_App hd (a, qual) ->
let a' = replace_term_in dbg from_term to_term a in
let hd' = replace_term_in dbg from_term to_term hd in
pack (Tv_App hd' (a', qual))
| Tv_Abs br body ->
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Abs br body')
| Tv_Arrow br c0 -> tm
| Tv_Type _ -> tm
| Tv_Refine bv sort ref ->
let sort' = replace_term_in dbg from_term to_term sort in
let ref' = replace_term_in dbg from_term to_term ref in
pack (Tv_Refine bv sort' ref')
| Tv_Const _ -> tm
| Tv_Uvar _ _ -> tm
| Tv_Let recf attrs bv ty def body ->
let def' = replace_term_in dbg from_term to_term def in
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Let recf attrs bv ty def' body')
| Tv_Match scrutinee ret_opt branches ->
let explore_branch (br: branch) : Tac branch =
let pat, body = br in
let body' = replace_term_in dbg from_term to_term body in
(pat, body')
in
let scrutinee' = replace_term_in dbg from_term to_term scrutinee in
let branches' = map explore_branch branches in
pack (Tv_Match scrutinee' ret_opt branches')
| Tv_AscribedT e ty tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
let ty' = replace_term_in dbg from_term to_term ty in
pack (Tv_AscribedT e' ty' tac use_eq)
| Tv_AscribedC e c tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
pack (Tv_AscribedC e' c tac use_eq)
| _ -> tm | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.fv",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.InteractiveHelpers.PostProcess.replace_term_in",
"FStar.Reflection.Types.binder",
"FStar.Reflection.V1.Data.Tv_Abs",
"FStar.Reflection.Types.comp",
"FStar.Reflection.Types.universe",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V1.Data.Tv_Refine",
"FStar.Reflection.V1.Data.vconst",
"Prims.nat",
"FStar.Reflection.Types.ctx_uvar_and_subst",
"Prims.list",
"FStar.Reflection.V1.Data.Tv_Let",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.match_returns_ascription",
"FStar.Reflection.V1.Data.branch",
"FStar.Reflection.V1.Data.Tv_Match",
"FStar.Tactics.Util.map",
"FStar.Reflection.V1.Data.pattern",
"FStar.Reflection.V1.Data.Tv_AscribedT",
"FStar.Reflection.V1.Data.Tv_AscribedC",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect",
"FStar.InteractiveHelpers.PostProcess.term_eq"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts
/// Look for an equality in a postcondition which can be used for rewriting.
val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term)
let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
(* Compute the post-condition *)
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty))
tinfo einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
(* Look for an equality in the post *)
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
(* If we found something, we return the updated environment,
* otherwise we can return the original one *)
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm
/// Given a list of parent terms (as generated by ``explore_term``), look for an
/// equality given by a post-condition which can be used to replace a term.
val find_context_equality :
dbg:bool
-> ge0:genv
-> tm:term
-> parents:list term_view
-> children:list term_view
-> Tac (genv & option term)
/// Auxiliary function which actually performs the search
let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv)
(parents children : list term_view) :
Tac (genv & option term) =
match parents with
| [] -> ge0, None
| tv :: parents' ->
print_dbg dbg ("[> find_context_equality:\n" ^
"- term : " ^ term_to_string tm ^ "\n" ^
"- parent: " ^ term_to_string tv);
(* We only consider let-bindings *)
match tv with
| Tv_Let _ _ bv' ty def _ ->
print_dbg dbg "Is Tv_Let";
let tm_info = compute_eterm_info dbg ge0.env def in
let einfo = tm_info.einfo in
(* If the searched term is a bv and the current let is the one which
* introduces it:
* - if the term is effectful, use it
* - otherwise, try to use its postcondition. If we don't find any
* equalities, some there *)
let let_bv_is_tm =
match opt_bv with
| Some tm_bv -> bv_eq tm_bv bv'
| None -> false
in
if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def
else
let ret_value = pack (Tv_Var bv') in
begin match find_equality_from_post dbg ge0 tm bv' ty ret_value
einfo parents children with
| ge1, Some p -> ge1, Some p
| _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
end
| _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
let find_context_equality dbg ge0 tm parents children =
let opt_bv =
match inspect tm with
| Tv_Var bv -> Some bv
| _ -> None
in
find_context_equality_aux dbg ge0 tm opt_bv parents children
/// Replace a subterm by another term
val replace_term_in : bool -> term -> term -> term -> Tac term | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val replace_term_in : bool -> term -> term -> term -> Tac term | [
"recursion"
] | FStar.InteractiveHelpers.PostProcess.replace_term_in | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
from_term: FStar.Reflection.Types.term ->
to_term: FStar.Reflection.Types.term ->
tm: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Reflection.Types.term | {
"end_col": 6,
"end_line": 592,
"start_col": 2,
"start_line": 548
} |
FStar.Tactics.Effect.Tac | val _split_conjunctions (ls: list term) (t: term) : Tac (list term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2 | val _split_conjunctions (ls: list term) (t: term) : Tac (list term)
let rec _split_conjunctions (ls: list term) (t: term) : Tac (list term) = | true | null | false | match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2 | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.list",
"FStar.Reflection.Types.term",
"Prims.Cons",
"FStar.InteractiveHelpers.PostProcess._split_conjunctions",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.PostProcess.is_conjunction"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val _split_conjunctions (ls: list term) (t: term) : Tac (list term) | [
"recursion"
] | FStar.InteractiveHelpers.PostProcess._split_conjunctions | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | ls: Prims.list FStar.Reflection.Types.term -> t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac (Prims.list FStar.Reflection.Types.term) | {
"end_col": 7,
"end_line": 302,
"start_col": 2,
"start_line": 297
} |
FStar.Tactics.Effect.Tac | val formula_construct (f: formula) : Tac string | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown" | val formula_construct (f: formula) : Tac string
let formula_construct (f: formula) : Tac string = | true | null | false | match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown" | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Reflection.V1.Formula.formula",
"FStar.Reflection.V1.Formula.comparison",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"FStar.Reflection.Types.fv",
"Prims.int",
"Prims.string"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)] | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val formula_construct (f: formula) : Tac string | [] | FStar.InteractiveHelpers.PostProcess.formula_construct | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: FStar.Reflection.V1.Formula.formula -> FStar.Tactics.Effect.Tac Prims.string | {
"end_col": 30,
"end_line": 423,
"start_col": 2,
"start_line": 408
} |
Prims.Tot | val mk_eq : eq_kind -> term -> term -> Tot term | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)] | val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 = | false | null | false | match k with
| Eq_Dec ty -> mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty -> mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)] | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.PostProcess.eq_kind",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V1.Derived.mk_app",
"Prims.Cons",
"FStar.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Data.Q_Implicit",
"FStar.Reflection.V1.Data.Q_Explicit",
"Prims.Nil"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term | false | true | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_eq : eq_kind -> term -> term -> Tot term | [] | FStar.InteractiveHelpers.PostProcess.mk_eq | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
k: FStar.InteractiveHelpers.PostProcess.eq_kind ->
t1: FStar.Reflection.Types.term ->
t2: FStar.Reflection.Types.term
-> FStar.Reflection.Types.term | {
"end_col": 64,
"end_line": 405,
"start_col": 2,
"start_line": 398
} |
FStar.Tactics.Effect.Tac | val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end | val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg = | true | null | false | print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
match term_is_assert_or_assume res'.res with
| None ->
mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^
term_to_string res.res)
| Some tm -> { res' with res = tm } | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.mfail",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Reflection.Types.term",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res",
"FStar.InteractiveHelpers.PostProcess.Mkexploration_result",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__parents",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__tgt_comp",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.PostProcess.term_is_assert_or_assume",
"Prims.list",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"FStar.InteractiveHelpers.Base.genv",
"FStar.InteractiveHelpers.Base.genv_push_bv",
"FStar.Pervasives.Native.None",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"FStar.InteractiveHelpers.PostProcess.find_focused_term_in_current_goal"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term) | [] | FStar.InteractiveHelpers.PostProcess.find_focused_assert_in_current_goal | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool
-> FStar.Tactics.Effect.Tac
(FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Reflection.Types.term) | {
"end_col": 5,
"end_line": 170,
"start_col": 2,
"start_line": 156
} |
Prims.Tot | val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a)) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue | val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t = | false | null | false | if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg
then print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t);
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [
"total"
] | [
"FStar.InteractiveHelpers.PostProcess.pred_explorer",
"Prims.bool",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.InteractiveHelpers.Base.genv",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Data.term_view",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.Types.ctrl_flag",
"FStar.Pervasives.Native.Some",
"FStar.InteractiveHelpers.PostProcess.mk_exploration_result",
"FStar.Tactics.Types.Abort",
"FStar.Pervasives.Native.None",
"FStar.Tactics.Types.Continue",
"Prims.unit",
"FStar.Tactics.V1.Builtins.print",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Reflection.Types.term",
"FStar.Tactics.V1.Builtins.pack",
"FStar.InteractiveHelpers.Base.term_view_construct",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.InteractiveHelpers.Base.mfail"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a)) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a)) | [] | FStar.InteractiveHelpers.PostProcess.find_predicated_term_explorer | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | pred: FStar.InteractiveHelpers.PostProcess.pred_explorer a -> dbg: Prims.bool
-> FStar.InteractiveHelpers.ExploreTerm.explorer (FStar.Pervasives.Native.option (FStar.InteractiveHelpers.PostProcess.exploration_result
a)) | {
"end_col": 26,
"end_line": 111,
"start_col": 2,
"start_line": 104
} |
FStar.Tactics.Effect.Tac | val is_conjunction : term -> Tac (option (term & term)) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None | val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t = | true | null | false | let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [x, Q_Explicit ; y, Q_Explicit] ->
(match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"] then Some (x, y) else None
| _ -> None)
| _ -> None | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"FStar.Reflection.Types.fv",
"Prims.op_BarBar",
"Prims.op_Equality",
"Prims.string",
"FStar.Reflection.Const.and_qn",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.name",
"FStar.Reflection.V1.Builtins.inspect_fv",
"FStar.Reflection.V1.Data.term_view",
"FStar.Tactics.V1.Builtins.inspect",
"FStar.Tactics.V1.SyntaxHelpers.collect_app",
"FStar.InteractiveHelpers.PostProcess.remove_b2t"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _' | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_conjunction : term -> Tac (option (term & term)) | [] | FStar.InteractiveHelpers.PostProcess.is_conjunction | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (FStar.Reflection.Types.term * FStar.Reflection.Types.term)) | {
"end_col": 13,
"end_line": 292,
"start_col": 22,
"start_line": 280
} |
FStar.Tactics.Effect.Tac | val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
(* Compute the post-condition *)
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty))
tinfo einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
(* Look for an equality in the post *)
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
(* If we found something, we return the updated environment,
* otherwise we can return the original one *)
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm | val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term)
let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children = | true | null | false | print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty)) tinfo
einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.bv",
"FStar.Reflection.Types.typ",
"FStar.InteractiveHelpers.Effectful.effect_info",
"Prims.list",
"FStar.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Propositions.proposition",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.PostProcess.find_subequality",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.option_to_string",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.Effectful.pre_post_to_propositions",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_type",
"FStar.Reflection.Types.binder",
"FStar.Reflection.V1.Derived.mk_binder",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_pre",
"FStar.InteractiveHelpers.Effectful.__proj__Mkeffect_info__item__ei_post",
"FStar.InteractiveHelpers.ExploreTerm.type_info",
"FStar.InteractiveHelpers.ExploreTerm.get_type_info_from_type"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts
/// Look for an equality in a postcondition which can be used for rewriting.
val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term) | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term) | [] | FStar.InteractiveHelpers.PostProcess.find_equality_from_post | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
ge0: FStar.InteractiveHelpers.Base.genv ->
tm: FStar.Reflection.Types.term ->
let_bv: FStar.Reflection.Types.bv ->
let_bvty: FStar.Reflection.Types.typ ->
ret_value: FStar.Reflection.Types.term ->
einfo: FStar.InteractiveHelpers.Effectful.effect_info ->
parents: Prims.list FStar.Reflection.V1.Data.term_view ->
children: Prims.list FStar.Reflection.V1.Data.term_view
-> FStar.Tactics.Effect.Tac
(FStar.InteractiveHelpers.Base.genv * FStar.Pervasives.Native.option FStar.Reflection.Types.term
) | {
"end_col": 27,
"end_line": 489,
"start_col": 2,
"start_line": 471
} |
FStar.Tactics.Effect.Tac | val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end | val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg = | true | null | false | let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
(match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: " ^
term_to_string g))
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality" | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"Prims.unit",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res",
"FStar.InteractiveHelpers.Base.mfail",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.PostProcess.find_focused_term",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Reflection.V1.Data.term_view",
"FStar.InteractiveHelpers.Base.mk_genv",
"FStar.Reflection.Types.bv",
"FStar.Pervasives.Native.tuple3",
"FStar.Reflection.Types.typ",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.InteractiveHelpers.ExploreTerm.uu___is_TC_Comp",
"FStar.Pervasives.Native.__proj__Some__item__v",
"FStar.InteractiveHelpers.ExploreTerm.safe_typ_or_comp",
"FStar.InteractiveHelpers.PostProcess.unsquash_equality",
"FStar.Reflection.Types.env",
"FStar.Tactics.V1.Derived.cur_env",
"FStar.Tactics.V1.Derived.cur_goal"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val find_focused_term_in_current_goal : bool -> Tac (exploration_result term) | [] | FStar.InteractiveHelpers.PostProcess.find_focused_term_in_current_goal | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | dbg: Prims.bool
-> FStar.Tactics.Effect.Tac
(FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Reflection.Types.term) | {
"end_col": 5,
"end_line": 151,
"start_col": 43,
"start_line": 133
} |
FStar.Tactics.Effect.Tac | val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts | val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res = | true | null | false | let ge = res.ge in
let opt_c = res.tgt_comp in
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv:option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
let ge2, (bv1: bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" then genv_push_fresh_bv ge1 "ret" ty else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
let is_assert = Some? (term_is_assert_or_assume studied_term) in
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let is_assert info ret_arg
opt_c parents []
in
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
let asserts =
if is_let then asserts else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
printout_success ge3 asserts | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Base.genv",
"FStar.InteractiveHelpers.Effectful.eterm_info",
"FStar.Pervasives.Native.option",
"FStar.Reflection.Types.bv",
"FStar.InteractiveHelpers.Propositions.assertions",
"FStar.InteractiveHelpers.Output.printout_success",
"Prims.unit",
"FStar.InteractiveHelpers.Propositions.mk_assertions",
"FStar.List.Tot.Base.append",
"FStar.InteractiveHelpers.Propositions.proposition",
"FStar.InteractiveHelpers.Propositions.__proj__Mkassertions__item__pres",
"FStar.InteractiveHelpers.Propositions.__proj__Mkassertions__item__posts",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Output.subst_shadowed_with_abs_in_assertions",
"FStar.InteractiveHelpers.Propositions.simp_filter_assertions",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"FStar.InteractiveHelpers.Propositions.simpl_norm_steps",
"FStar.InteractiveHelpers.Effectful.eterm_info_to_assertions",
"FStar.Reflection.V1.Data.term_view",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.snd",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__parents",
"FStar.InteractiveHelpers.Base.opt_tapply",
"FStar.Tactics.V1.Builtins.pack",
"FStar.Reflection.V1.Data.Tv_Var",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.InteractiveHelpers.PostProcess.term_is_assert_or_assume",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.InteractiveHelpers.Base.genv_to_string",
"FStar.InteractiveHelpers.Base.term_construct",
"FStar.Pervasives.Native.tuple6",
"FStar.Reflection.Types.typ",
"FStar.Pervasives.Native.Mktuple6",
"FStar.Pervasives.Native.Some",
"FStar.InteractiveHelpers.Effectful.compute_eterm_info",
"FStar.InteractiveHelpers.Base.genv_push_fresh_bv",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Equality",
"FStar.Tactics.Unseal.unseal",
"FStar.Reflection.V1.Data.__proj__Mkbv_view__item__bv_ppname",
"FStar.InteractiveHelpers.Base.abv_to_string",
"FStar.Reflection.V1.Data.bv_view",
"Prims.precedes",
"FStar.Reflection.V1.Builtins.inspect_bv",
"FStar.InteractiveHelpers.Base.genv_push_bv",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.fst",
"FStar.InteractiveHelpers.Base.genv_get_from_name",
"FStar.Tactics.V1.Derived.name_of_bv",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res",
"FStar.Tactics.V1.Builtins.inspect",
"FStar.InteractiveHelpers.ExploreTerm.typ_or_comp",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__tgt_comp",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit | [] | FStar.InteractiveHelpers.PostProcess.analyze_effectful_term | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
with_gpre: Prims.bool ->
with_gpost: Prims.bool ->
res: FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 30,
"end_line": 243,
"start_col": 57,
"start_line": 185
} |
FStar.Tactics.Effect.Tac | val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Output",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Effectful",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Propositions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.ExploreTerm",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.InteractiveHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let unfold_in_assert_or_assume dbg ares =
print_dbg dbg ("[> unfold_in_assert_or_assume:\n" ^ term_to_string ares.res);
(* Find the focused term inside the assert, and on which side of the
* equality if the assert is an equality *)
let find_focused_in_term t =
find_focused_term dbg false ares.ge ares.parents ares.tgt_comp t
in
let find_in_whole_term () : Tac _ =
match find_focused_in_term ares.res with
| Some res ->
ares.res, res, (fun x -> x <: Tac term), true
| None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
in
(* - subterm: the subterm of the assertion in which we found the focused term
* (if an equality, left or right operand, otherwise whole assertion)
* - unf_res: the result of the exploration for the focused term inside the
* assertion, which gives the term to unfold
* - rebuild: a Tot function which, given a term, rebuilds the equality by
* replacing the above subterm with the given term
* - insert_before: whether to insert the new assertion before or after the
* current assertion in the user file *)
let subterm, unf_res, (rebuild : term -> Tac term), insert_before =
let _ = print_dbg dbg ("Assertion: " ^ term_to_string ares.res) in
match is_eq dbg ares.res with
| Some (kd, l, r) ->
print_dbg dbg "The assertion is an equality";
begin match find_focused_in_term l with
| Some res ->
print_dbg dbg ("Found focused term in left operand:" ^
"\n- left : " ^ term_to_string l ^
"\n- right : " ^ term_to_string r ^
"\n- focused: " ^ term_to_string res.res);
let rebuild t : Tac term = mk_eq kd t r in
l, res, rebuild, true
| None ->
begin match find_focused_in_term r with
| Some res ->
print_dbg dbg ("Found focused term in right operand:" ^
"\n- left : " ^ term_to_string l ^
"\n- right : " ^ term_to_string r ^
"\n- focused: " ^ term_to_string res.res);
let rebuild (t : term) : Tac term = mk_eq kd l t in
r, res, rebuild, false
| None ->
mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
end
end
| None ->
print_dbg dbg "The assertion is not an equality";
find_in_whole_term ()
in
print_dbg dbg ("Found subterm in assertion/assumption:\n" ^
"- subterm: " ^ term_to_string subterm ^ "\n" ^
"- focused term: " ^ term_to_string unf_res.res);
(* Unfold the term *)
let res_view = inspect unf_res.res in
let ge1, opt_unf_tm =
match res_view with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier: " ^ fv_to_string fv);
(* The easy case: just use the normalizer *)
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ares.ge.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ares.ge, Some subterm'
| _ ->
(* Look for an equality given by a previous post-condition. In the case
* the term is a bv, we can also use the let-binding which introduces it,
* if it is pure. *)
let parents = List.Tot.map snd ares.parents in
let opt_bvty : option (bv & typ) =
match res_view with
| Tv_Var bv ->
print_dbg dbg ("The focused term is a local variable: " ^ bv_to_string bv);
(* Check that the binder was not introduced by an abstraction inside the assertion *)
if not (Some? (genv_get ares.ge bv)) then
mfail "unfold_in_assert_or_assume: can't unfold a variable locally introduced in an assertion";
Some (bv, pack_ln Tv_Unknown) // FIXME
| _ ->
print_dbg dbg ("The focused term is an arbitrary term: " ^ term_to_string unf_res.res);
None
in
let ge1, eq_tm = find_context_equality dbg ares.ge unf_res.res parents [] in
(* Check if we found an equality *)
let opt_eq_tm =
match eq_tm with
| Some eq_tm -> Some eq_tm
| _ -> None
in
(* Apply it *)
let subterm' =
match opt_bvty, opt_eq_tm with
| Some bvty, Some eq_tm -> Some (apply_subst ge1.env subterm [(bvty, eq_tm)])
| None, Some eq_tm -> Some (replace_term_in dbg unf_res.res eq_tm subterm)
| _ -> None
in
ge1, subterm'
in
(* If we couldn't unfold the term, check if it is a top-level identifier with
* implicit parameters (it may happen that the user calls the command on a
* top-level identifier which has implicit parameters without providing
* those parameters, in which case the focused term is the identifier applied
* to those implicits inferred by F*, and thus an app and not an fvar).
* Note that so far we have no way to check if the implicit parameters have
* been explicitly provided by the user or not, which is why we can't do better
* than greedy tests.*)
let ge2, unf_tm =
match opt_unf_tm with
| Some unf_tm -> ge1, unf_tm
| None ->
begin match inspect (strip_implicit_parameters unf_res.res) with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier with implicit parameters: "
^ fv_to_string fv);
(* The easy case: just use the normalizer *)
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ge1.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ge1, subterm'
| _ ->
mfail ("unfold_in_assert_or_assume: " ^
"couldn't find equalities with which to rewrite: " ^
term_to_string unf_res.res)
end
in
(* Create the assertions to output *)
let final_assert = rebuild unf_tm in
let final_assert = prettify_term dbg final_assert in
print_dbg dbg ("-> Final assertion:\n" ^ term_to_string final_assert);
let asserts =
if insert_before then mk_assertions [final_assert] [] else mk_assertions [] [final_assert]
in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 None asserts in
(* Output *)
printout_success ge3 asserts | val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit
let unfold_in_assert_or_assume dbg ares = | true | null | false | print_dbg dbg ("[> unfold_in_assert_or_assume:\n" ^ term_to_string ares.res);
let find_focused_in_term t = find_focused_term dbg false ares.ge ares.parents ares.tgt_comp t in
let find_in_whole_term () : Tac _ =
match find_focused_in_term ares.res with
| Some res -> ares.res, res, (fun x -> x <: Tac term), true
| None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert"
in
let subterm, unf_res, (rebuild: (term -> Tac term)), insert_before =
let _ = print_dbg dbg ("Assertion: " ^ term_to_string ares.res) in
match is_eq dbg ares.res with
| Some (kd, l, r) ->
print_dbg dbg "The assertion is an equality";
(match find_focused_in_term l with
| Some res ->
print_dbg dbg
("Found focused term in left operand:" ^
"\n- left : " ^
term_to_string l ^
"\n- right : " ^ term_to_string r ^ "\n- focused: " ^ term_to_string res.res);
let rebuild t : Tac term = mk_eq kd t r in
l, res, rebuild, true
| None ->
match find_focused_in_term r with
| Some res ->
print_dbg dbg
("Found focused term in right operand:" ^
"\n- left : " ^
term_to_string l ^
"\n- right : " ^ term_to_string r ^ "\n- focused: " ^ term_to_string res.res);
let rebuild (t: term) : Tac term = mk_eq kd l t in
r, res, rebuild, false
| None -> mfail "unfold_in_assert_or_assume: could not find a focused term in the assert")
| None ->
print_dbg dbg "The assertion is not an equality";
find_in_whole_term ()
in
print_dbg dbg
("Found subterm in assertion/assumption:\n" ^
"- subterm: " ^ term_to_string subterm ^ "\n" ^ "- focused term: " ^ term_to_string unf_res.res);
let res_view = inspect unf_res.res in
let ge1, opt_unf_tm =
match res_view with
| Tv_FVar fv ->
print_dbg dbg ("The focused term is a top identifier: " ^ fv_to_string fv);
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ares.ge.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ares.ge, Some subterm'
| _ ->
let parents = List.Tot.map snd ares.parents in
let opt_bvty:option (bv & typ) =
match res_view with
| Tv_Var bv ->
print_dbg dbg ("The focused term is a local variable: " ^ bv_to_string bv);
if not (Some? (genv_get ares.ge bv))
then
mfail "unfold_in_assert_or_assume: can't unfold a variable locally introduced in an assertion"
;
Some (bv, pack_ln Tv_Unknown)
| _ ->
print_dbg dbg ("The focused term is an arbitrary term: " ^ term_to_string unf_res.res);
None
in
let ge1, eq_tm = find_context_equality dbg ares.ge unf_res.res parents [] in
let opt_eq_tm =
match eq_tm with
| Some eq_tm -> Some eq_tm
| _ -> None
in
let subterm' =
match opt_bvty, opt_eq_tm with
| Some bvty, Some eq_tm -> Some (apply_subst ge1.env subterm [(bvty, eq_tm)])
| None, Some eq_tm -> Some (replace_term_in dbg unf_res.res eq_tm subterm)
| _ -> None
in
ge1, subterm'
in
let ge2, unf_tm =
match opt_unf_tm with
| Some unf_tm -> ge1, unf_tm
| None ->
match inspect (strip_implicit_parameters unf_res.res) with
| Tv_FVar fv ->
print_dbg dbg
("The focused term is a top identifier with implicit parameters: " ^ fv_to_string fv);
let fname = flatten_name (inspect_fv fv) in
let subterm' = norm_term_env ge1.env [delta_only [fname]; zeta] subterm in
print_dbg dbg ("Normalized subterm: " ^ term_to_string subterm');
ge1, subterm'
| _ ->
mfail ("unfold_in_assert_or_assume: " ^
"couldn't find equalities with which to rewrite: " ^ term_to_string unf_res.res)
in
let final_assert = rebuild unf_tm in
let final_assert = prettify_term dbg final_assert in
print_dbg dbg ("-> Final assertion:\n" ^ term_to_string final_assert);
let asserts =
if insert_before then mk_assertions [final_assert] [] else mk_assertions [] [final_assert]
in
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 None asserts in
printout_success ge3 asserts | {
"checked_file": "FStar.InteractiveHelpers.PostProcess.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.InteractiveHelpers.Propositions.fst.checked",
"FStar.InteractiveHelpers.Output.fst.checked",
"FStar.InteractiveHelpers.ExploreTerm.fst.checked",
"FStar.InteractiveHelpers.Effectful.fst.checked",
"FStar.InteractiveHelpers.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.InteractiveHelpers.PostProcess.fst"
} | [] | [
"Prims.bool",
"FStar.InteractiveHelpers.PostProcess.exploration_result",
"FStar.Reflection.Types.term",
"FStar.InteractiveHelpers.Base.genv",
"FStar.Pervasives.Native.option",
"FStar.InteractiveHelpers.Propositions.assertions",
"FStar.InteractiveHelpers.Output.printout_success",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.InteractiveHelpers.Output.subst_shadowed_with_abs_in_assertions",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Types.bv",
"FStar.InteractiveHelpers.Propositions.mk_assertions",
"Prims.Cons",
"FStar.InteractiveHelpers.Propositions.proposition",
"Prims.Nil",
"FStar.InteractiveHelpers.Base.print_dbg",
"Prims.string",
"Prims.op_Hat",
"FStar.Tactics.V1.Builtins.term_to_string",
"FStar.InteractiveHelpers.Base.prettify_term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Reflection.Types.fv",
"FStar.Tactics.V1.Builtins.norm_term_env",
"FStar.InteractiveHelpers.Base.__proj__Mkgenv__item__env",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.zeta",
"FStar.Reflection.V1.Derived.flatten_name",
"FStar.Reflection.V1.Builtins.inspect_fv",
"FStar.Reflection.V1.Derived.fv_to_string",
"FStar.Reflection.V1.Data.term_view",
"FStar.InteractiveHelpers.Base.mfail",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__res",
"FStar.Tactics.V1.Builtins.inspect",
"FStar.InteractiveHelpers.PostProcess.strip_implicit_parameters",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__ge",
"FStar.Pervasives.Native.Some",
"FStar.Reflection.Types.typ",
"FStar.InteractiveHelpers.Base.apply_subst",
"FStar.InteractiveHelpers.PostProcess.replace_term_in",
"FStar.InteractiveHelpers.PostProcess.find_context_equality",
"FStar.Reflection.V1.Builtins.pack_ln",
"FStar.Reflection.V1.Data.Tv_Unknown",
"Prims.op_Negation",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple3",
"FStar.InteractiveHelpers.Base.genv_get",
"FStar.Tactics.V1.Derived.bv_to_string",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.snd",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__parents",
"FStar.Pervasives.Native.tuple4",
"FStar.InteractiveHelpers.PostProcess.eq_kind",
"FStar.Pervasives.Native.Mktuple4",
"FStar.InteractiveHelpers.PostProcess.mk_eq",
"FStar.InteractiveHelpers.PostProcess.is_eq",
"FStar.InteractiveHelpers.PostProcess.find_focused_term",
"FStar.InteractiveHelpers.PostProcess.__proj__Mkexploration_result__item__tgt_comp"
] | [] | module FStar.InteractiveHelpers.PostProcess
open FStar.List
open FStar.Tactics
open FStar.Mul
open FStar.InteractiveHelpers.Base
open FStar.InteractiveHelpers.ExploreTerm
open FStar.InteractiveHelpers.Propositions
open FStar.InteractiveHelpers.Effectful
open FStar.InteractiveHelpers.Output
let term_eq = FStar.Tactics.term_eq_old
/// The high-level post-processing tactics, used to retrieve some specific
/// information from the context and generate output which can be exploited
/// on the IDE side.
#push-options "--z3rlimit 15 --fuel 0 --ifuel 1"
(*** General utilities *)
/// We declare some identifiers that we will use to guide the meta processing
assume type meta_info
assume val focus_on_term : meta_info
let end_proof () =
tadmit_t (`())
let unsquash_equality (t:term) : Tac (option (term & term)) =
begin match term_as_formula t with
| Comp (Eq _) l r -> Some (l, r)
| _ -> None
end
#push-options "--ifuel 2"
let pp_explore (dbg dfs : bool)
(#a : Type0)
(f : explorer a)
(x : a) :
Tac unit =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> pp_explore:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
let x = explore_term dbg dfs #a f x ge [] c l in
end_proof ()
| _ -> mfail "pp_explore: not a squashed equality"
end
#pop-options
/// This function goes through the goal, which is presumed to be a squashed equality,
/// and prints all the subterms of its left operand. Very useful for debugging.
val pp_explore_print_goal : unit -> Tac unit
let pp_explore_print_goal () =
let f : explorer unit =
fun _ _ _ _ _ -> ((), Continue)
in
pp_explore true false f ()
/// Check for meta-identifiers. Note that we can't simply use ``term_eq`` which
/// sometimes unexpectedly fails (maybe because of information hidden to Meta-F*)
val is_focus_on_term : term -> Tac bool
let is_focus_on_term t = is_fvar t (`%focus_on_term)
/// Check if a term is an assertion or an assumption and return its content
/// if it is the case.
val term_is_assert_or_assume : term -> Tac (option term)
let term_is_assert_or_assume t =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
if is_any_fvar a [`%Prims._assert; `%FStar.Pervasives.assert_norm; `%Prims._assume]
then Some a
else None
| _ -> None
/// Check if the given term view is of the form: 'let _ = focus_on_term in body'
/// Returns 'body' if it is the case.
val is_focused_term : term_view -> Tac (option term)
let is_focused_term tv =
match tv with
| Tv_Let recf attrs _ _ def body ->
if is_focus_on_term def then Some body else None
| _ -> None
noeq type exploration_result (a : Type)= {
ge : genv;
parents : list (genv & term_view);
tgt_comp : option typ_or_comp;
res : a;
}
let mk_exploration_result = Mkexploration_result
let pred_explorer (a:Type) =
genv -> list (genv & term_view) -> option typ_or_comp -> term_view ->
Tac (option a)
val find_predicated_term_explorer : #a:Type0 -> pred_explorer a -> bool ->
explorer (option (exploration_result a))
let find_predicated_term_explorer #a pred dbg acc ge pl opt_c t =
if Some? acc then mfail "find_focused_term_explorer: non empty accumulator";
if dbg then
begin
print ("[> find_focused_term_explorer: " ^ term_view_construct t ^ ":\n" ^ term_to_string t)
end;
match pred ge pl opt_c t with
| Some ft -> Some (mk_exploration_result ge pl opt_c ft), Abort
| None -> None, Continue
val find_predicated_term : #a:Type0 -> pred_explorer a -> bool -> bool ->
genv -> list (genv & term_view) ->
option typ_or_comp -> term ->
Tac (option (exploration_result a))
let find_predicated_term #a pred dbg dfs ge pl opt_c t =
fst (explore_term dbg dfs #(option (exploration_result a))
(find_predicated_term_explorer #a pred dbg)
None ge pl opt_c t)
val _is_focused_term_explorer : pred_explorer term
let _is_focused_term_explorer ge pl opt_c tv =
is_focused_term tv
val find_focused_term : bool -> bool -> genv -> list (genv & term_view) -> option typ_or_comp -> term ->
Tac (option (exploration_result term))
let find_focused_term dbg dfs ge pl opt_c t =
find_predicated_term #term _is_focused_term_explorer dbg dfs ge pl opt_c t
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_term_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_term_in_current_goal dbg =
let g = cur_goal () in
let e = cur_env () in
print_dbg dbg ("[> find_focused_assert_in_current_goal:\n" ^ term_to_string g);
begin match unsquash_equality g with
| Some (l, _) ->
let c = safe_typ_or_comp dbg e l in
let ge = mk_genv e [] [] in
print_dbg dbg ("[> About to explore term:\n" ^ term_to_string l);
begin match find_focused_term dbg true ge [] c l with
| Some res ->
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
res
| None ->
mfail ("find_focused_term_in_current_goal: could not find a focused term in the current goal: "
^ term_to_string g)
end
| _ -> mfail "find_focused_term_in_current_goal: not a squashed equality"
end
/// This function raises a MetaAnalysis exception if it can't find a focused term
val find_focused_assert_in_current_goal : bool -> Tac (exploration_result term)
let find_focused_assert_in_current_goal dbg =
print_dbg dbg ("[> find_focused_assert_in_current_goal");
let res = find_focused_term_in_current_goal dbg in
print_dbg dbg ("[> Found focused term:\n" ^ term_to_string res.res);
(* Check that it is an assert or an assume, retrieve the assertion *)
let res' =
match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
let ge' = genv_push_bv res.ge bv0 ty false None in
({ res with res = fterm; ge = ge' })
| _ -> res
in
begin match term_is_assert_or_assume res'.res with
| None -> mfail ("find_focused_assert_in_current_goal: the found focused term is not an assertion or an assumption:" ^ term_to_string res.res)
| Some tm -> { res' with res = tm }
end
(*** Analyze effectful term *)
/// Analyze a term in order to print properly instantiated pre/postconditions
/// and type conditions.
/// with_globals states whether to analyze the target pre/post together with the
/// focused term.
val analyze_effectful_term :
dbg:bool
-> with_gpre:bool
-> with_gpost:bool
-> res:exploration_result term
-> Tac unit
let analyze_effectful_term dbg with_gpre with_gpost res =
let ge = res.ge in
let opt_c = res.tgt_comp in
(* Analyze the effectful term and check whether it is a 'let' or not *)
let ge1, studied_term, info, ret_bv, shadowed_bv, is_let =
begin match inspect res.res with
| Tv_Let _ _ bv0 ty fterm _ ->
(* Before pushing the binder, check if it shadows another variable.
* If it is the case, we will need it to correctly output the pre
* and post-assertions (because for the pre-assertions the variable
* will not be shadowed yet, while it will be the case for the post-
* assertions) *)
print_dbg dbg ("Restraining to: " ^ term_to_string fterm);
let shadowed_bv : option bv =
match genv_get_from_name ge (name_of_bv bv0) with
| None -> None
| Some (sbv, _) -> Some (fst sbv)
in
let ge1 = genv_push_bv ge bv0 ty false None in
(* If the bv name is "uu___", introduce a fresh variable and use it instead:
* the underscore might have been introduced when desugaring a let using
* tuples. If doing that is not necessary, the introduced variable will
* not appear in the generated assertions anyway. *)
let ge2, (bv1 : bv) =
let bvv0 = inspect_bv bv0 in
let _ = print_dbg dbg ("Variable bound in let: " ^ abv_to_string bv0) in
if unseal bvv0.bv_ppname = "uu___" (* this is a bit hacky *)
then genv_push_fresh_bv ge1 "ret" ty
else ge1, bv0
in
let info = compute_eterm_info dbg ge2.env fterm in
(ge2, fterm, (info <: eterm_info), Some bv1, shadowed_bv, true)
| _ -> (ge, res.res, compute_eterm_info dbg ge.env res.res, None, None, false)
end
in
print_dbg dbg ("[> Focused term constructor: " ^ term_construct studied_term);
print_dbg dbg ("[> Environment information (after effect analysis):\n" ^ genv_to_string ge1);
(* Check if the considered term is an assert, in which case we will only
* display the precondition (otherwise we introduce too many assertions
* in the context) *)
let is_assert = Some? (term_is_assert_or_assume studied_term) in
(* Instantiate the refinements *)
(* TODO: use bv rather than term for ret_arg *)
let ret_arg = opt_tapply (fun x -> pack (Tv_Var x)) ret_bv in
let parents = List.Tot.map snd res.parents in
let ge2, asserts =
eterm_info_to_assertions dbg with_gpre with_gpost ge1 studied_term is_let
is_assert info ret_arg opt_c parents [] in
(* Simplify and filter *)
let asserts = simp_filter_assertions ge2.env simpl_norm_steps asserts in
(* Introduce fresh variables for the shadowed ones and substitute *)
let ge3, asserts = subst_shadowed_with_abs_in_assertions dbg ge2 shadowed_bv asserts in
(* If not a let, insert all the assertions before the term *)
let asserts =
if is_let then asserts
else mk_assertions (List.Tot.append asserts.pres asserts.posts) []
in
(* Print *)
printout_success ge3 asserts
[@plugin]
val pp_analyze_effectful_term : bool -> bool -> bool -> unit -> Tac unit
let pp_analyze_effectful_term dbg with_gpre with_gpost () =
try
let res = find_focused_term_in_current_goal dbg in
analyze_effectful_term dbg with_gpre with_gpost res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Split conjunctions *)
/// Split an assert made of conjunctions so that there is one assert per
/// conjunction. We try to be a bit smart. For instance, if the assertion is of
/// the form:
/// [> assert(let Construct x1 ... xn = e in A1 /\ ... /\ An);
/// We generate:
/// [> assert(let Construct x1 ... xn = e in A1);
/// [> ...
/// [> assert(let Construct x1 ... xn = e in An);
/// Remove ``b2t`` if it is the head of the term
val remove_b2t : term -> Tac term
let remove_b2t (t:term) : Tac term =
match inspect t with
| Tv_App hd (a, Q_Explicit) ->
begin match inspect hd with
| Tv_FVar fv ->
if fv_eq_name fv b2t_qn then a else t
| _ -> t
end
| _ -> t
// TODO: gather all the functions like split_conjunctions, is_eq...
/// Try to destruct a term of the form '_ && _' or '_ /\ _'
val is_conjunction : term -> Tac (option (term & term))
let is_conjunction t =
let t = remove_b2t t in
let hd, params = collect_app t in
match params with
| [(x,Q_Explicit);(y,Q_Explicit)] ->
begin match inspect hd with
| Tv_FVar fv ->
let fvn = inspect_fv fv in
if fvn = and_qn || fvn = ["Prims"; "op_AmpAmp"]
then Some (x, y) else None
| _ -> None
end
| _ -> None
val split_conjunctions : term -> Tac (list term)
let rec _split_conjunctions (ls : list term) (t : term) : Tac (list term) =
match is_conjunction t with
| None -> t :: ls
| Some (l, r) ->
let ls1 = _split_conjunctions ls r in
let ls2 = _split_conjunctions ls1 l in
ls2
let split_conjunctions t =
_split_conjunctions [] t
/// Split a term of the form:
/// [> let Constuct x1 ... xn = x in A1 /\ ... /\ Am
/// into m terms:
/// [> let Constuct x1 ... xn = x in A1
/// ...
/// [> let Constuct x1 ... xn = x in Am
val split_conjunctions_under_match : bool -> term -> Tac (list term)
let split_conjunctions_under_match dbg t =
let t1 = remove_b2t t in
print_dbg dbg ("[> split_conjunctions_under_match: " ^ term_construct t1);
match inspect t1 with
| Tv_Match scrut ret_opt [(pat, br)] ->
let tl = split_conjunctions br in
map (fun x -> pack (Tv_Match scrut ret_opt [(pat, x)])) tl
| _ ->
(* Not of the proper shape: return the original term *)
[t]
val split_assert_conjs : bool -> exploration_result term -> Tac unit
let split_assert_conjs dbg res =
let ge0 = res.ge in
(* Simplify the term (it may be an abstraction applied to some parameters) *)
let t = norm_term_env ge0.env simpl_norm_steps res.res in
(* Split the conjunctions *)
let conjs = split_conjunctions t in
(* If there is only one conjunction, check if it is of the following form
* and try to split:
* [> let Construct x1 .. xn = x in A1 /\ ... /\ Am
*)
let conjs =
if List.length conjs = 1 then split_conjunctions_under_match dbg t
else conjs
in
let asserts = mk_assertions conjs [] in
(* Print *)
printout_success ge0 asserts
[@plugin]
val pp_split_assert_conjs : bool -> unit -> Tac unit
let pp_split_assert_conjs dbg () =
try
let res = find_focused_assert_in_current_goal dbg in
split_assert_conjs dbg res;
end_proof ()
with | MetaAnalysis msg -> printout_failure msg; end_proof ()
| err -> (* Shouldn't happen, so transmit the exception for debugging *) raise err
(*** Term unfolding in assert *)
/// Unfold/rewrite a term in an assert.
/// If the term is a (recursive) top-level identifier, unfold it.
/// Otherwise look for an equality or a pure let-binding to replace it with.
/// If the assert is an equality, unfold/rewrite only on the side chosen by the user.
// TODO: use "kind" keyword rather than type above
/// An equality kind
noeq type eq_kind =
| Eq_Dec : typ -> eq_kind (* = *)
| Eq_Undec : typ -> eq_kind (* == *)
| Eq_Hetero : typ -> typ -> eq_kind (* === *)
/// Deconstruct an equality
// We use our own construct because ``term_as_formula`` doesn't always work
// TODO: update ``term_as_formula``
val is_eq : bool -> term -> Tac (option (eq_kind & term & term))
let is_eq dbg t =
let t = remove_b2t t in
print_dbg dbg ("[> is_eq: " ^ term_to_string t);
let hd, params = collect_app t in
print_dbg dbg ("- hd:\n" ^ term_to_string hd);
print_dbg dbg ("- parameters:\n" ^ list_to_string (fun (x, y) -> term_to_string x) params);
match inspect hd with
| Tv_FVar fv ->
begin match params with
| [(a,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_any_fvar a [`%Prims.op_Equality; `%Prims.equals; "Prims.op_Equals"] then
Some ((Eq_Dec a), x, y)
else if is_any_fvar a [`%Prims.eq2; "Prims.op_Equals_Equals"] then
Some ((Eq_Undec a), x, y)
else None
| [(a,Q_Implicit);(b,Q_Implicit);(x,Q_Explicit);(y,Q_Explicit)] ->
if is_fvar a (`%Prims.op_Equals_Equals_Equals) then
Some ((Eq_Hetero a b), x, y)
else None
| _ -> None
end
| _ -> None
/// Reconstruct an equality
val mk_eq : eq_kind -> term -> term -> Tot term
let mk_eq k t1 t2 =
match k with
| Eq_Dec ty ->
mk_app (`Prims.op_Equality) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Undec ty ->
mk_app (`Prims.eq2) [(ty, Q_Implicit); (t1, Q_Explicit); (t2, Q_Explicit)]
| Eq_Hetero ty1 ty2 ->
mk_app Prims.(`( === )) [(ty1, Q_Implicit); (ty2, Q_Implicit);
(t1, Q_Explicit); (t2, Q_Explicit)]
let formula_construct (f : formula) : Tac string =
match f with
| True_ -> "True_"
| False_ -> "False_"
| Comp _ _ _ -> "Comp"
| And _ _ -> "And"
| Or _ _ -> "Or"
| Not _ -> "Not"
| Implies _ _ -> "Implies"
| Iff _ _ -> "Iff"
| Forall _ _ _ -> "Forall"
| Exists _ _ _ -> "Exists"
| App _ _ -> "Apply"
| Name _ -> "Name"
| FV _ -> "FV"
| IntLit _ -> "IntLit"
| F_Unknown -> "F_Unknown"
/// Check if a proposition is an equality which can be used to rewrite a term.
/// Return the operand of the equality which the term is equal to if it is the case.
val is_equality_for_term : bool -> term -> term -> Tac (option term)
let is_equality_for_term dbg tm p =
print_dbg dbg ("[> is_equality_for_term:" ^
"\n- term: " ^ term_to_string tm ^
"\n- prop: " ^ term_to_string p);
(* Specialize equality for bv - TODO: not sure if necessary, but I had problems
* in the past *)
let check_eq : term -> Tac bool =
match inspect tm with
| Tv_Var bv ->
(fun tm' -> match inspect tm' with | Tv_Var bv' -> bv_eq bv bv' | _ -> false)
| _ -> (fun tm' -> term_eq tm tm')
in
match is_eq dbg p with
| Some (ekind, l, r) ->
(* We ignore heterogeneous equality, because it risks to cause havoc at
* typing after substitution *)
print_dbg dbg ("Term is eq: " ^ term_to_string l ^ " = " ^ term_to_string r);
if Eq_Hetero? ekind then
begin
print_dbg dbg "Ignoring heterogeneous equality";
None
end
else if check_eq l then Some r
else if check_eq r then Some l
else None
| _ ->
print_dbg dbg "Term is not eq";
None
val find_subequality : bool -> term -> term -> Tac (option term)
let find_subequality dbg tm p =
print_dbg dbg ("[> find_subequality:" ^
"\n- ter : " ^ term_to_string tm ^
"\n- props: " ^ term_to_string p);
let conjuncts = split_conjunctions p in
print_dbg dbg ("Conjuncts:\n" ^ list_to_string term_to_string conjuncts);
tryPick (is_equality_for_term dbg tm) conjuncts
/// Look for an equality in a postcondition which can be used for rewriting.
val find_equality_from_post :
bool -> genv -> term -> bv -> typ -> term -> effect_info ->
list term_view -> list term_view -> Tac (genv & option term)
let find_equality_from_post dbg ge0 tm let_bv let_bvty ret_value einfo parents children =
print_dbg dbg "[> find_equality_from_post";
let tinfo = get_type_info_from_type let_bvty in
(* Compute the post-condition *)
let ge1, _, post_prop =
pre_post_to_propositions dbg ge0 einfo.ei_type ret_value (Some (mk_binder let_bv let_bvty))
tinfo einfo.ei_pre einfo.ei_post parents children
in
print_dbg dbg ("Computed post: " ^ option_to_string term_to_string post_prop);
(* Look for an equality in the post *)
let res =
match post_prop with
| None -> None
| Some p -> find_subequality dbg tm p
in
(* If we found something, we return the updated environment,
* otherwise we can return the original one *)
match res with
| None -> ge0, None
| Some tm -> ge1, Some tm
/// Given a list of parent terms (as generated by ``explore_term``), look for an
/// equality given by a post-condition which can be used to replace a term.
val find_context_equality :
dbg:bool
-> ge0:genv
-> tm:term
-> parents:list term_view
-> children:list term_view
-> Tac (genv & option term)
/// Auxiliary function which actually performs the search
let rec find_context_equality_aux dbg ge0 tm (opt_bv : option bv)
(parents children : list term_view) :
Tac (genv & option term) =
match parents with
| [] -> ge0, None
| tv :: parents' ->
print_dbg dbg ("[> find_context_equality:\n" ^
"- term : " ^ term_to_string tm ^ "\n" ^
"- parent: " ^ term_to_string tv);
(* We only consider let-bindings *)
match tv with
| Tv_Let _ _ bv' ty def _ ->
print_dbg dbg "Is Tv_Let";
let tm_info = compute_eterm_info dbg ge0.env def in
let einfo = tm_info.einfo in
(* If the searched term is a bv and the current let is the one which
* introduces it:
* - if the term is effectful, use it
* - otherwise, try to use its postcondition. If we don't find any
* equalities, some there *)
let let_bv_is_tm =
match opt_bv with
| Some tm_bv -> bv_eq tm_bv bv'
| None -> false
in
if let_bv_is_tm && effect_type_is_pure einfo.ei_type then ge0, Some def
else
let ret_value = pack (Tv_Var bv') in
begin match find_equality_from_post dbg ge0 tm bv' ty ret_value
einfo parents children with
| ge1, Some p -> ge1, Some p
| _, None -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
end
| _ -> find_context_equality_aux dbg ge0 tm opt_bv parents' (tv :: children)
let find_context_equality dbg ge0 tm parents children =
let opt_bv =
match inspect tm with
| Tv_Var bv -> Some bv
| _ -> None
in
find_context_equality_aux dbg ge0 tm opt_bv parents children
/// Replace a subterm by another term
val replace_term_in : bool -> term -> term -> term -> Tac term
let rec replace_term_in dbg from_term to_term tm =
if term_eq from_term tm then to_term else
match inspect tm with
| Tv_Var _ | Tv_BVar _ | Tv_FVar _ -> tm
| Tv_App hd (a, qual) ->
let a' = replace_term_in dbg from_term to_term a in
let hd' = replace_term_in dbg from_term to_term hd in
pack (Tv_App hd' (a', qual))
| Tv_Abs br body ->
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Abs br body')
| Tv_Arrow br c0 -> tm (* TODO: we might want to explore that *)
| Tv_Type _ -> tm
| Tv_Refine bv sort ref ->
let sort' = replace_term_in dbg from_term to_term sort in
let ref' = replace_term_in dbg from_term to_term ref in
pack (Tv_Refine bv sort' ref')
| Tv_Const _ -> tm
| Tv_Uvar _ _ -> tm
| Tv_Let recf attrs bv ty def body ->
(* GM 2023-04-27: leaving ty untouched, old code did not
descend into sort. *)
let def' = replace_term_in dbg from_term to_term def in
let body' = replace_term_in dbg from_term to_term body in
pack (Tv_Let recf attrs bv ty def' body')
| Tv_Match scrutinee ret_opt branches -> //AR: TODO: account for the returns annotation
(* Auxiliary function to explore the branches *)
let explore_branch (br : branch) : Tac branch =
(* Only explore the branch body *)
let pat, body = br in
let body' = replace_term_in dbg from_term to_term body in
(pat, body')
in
let scrutinee' = replace_term_in dbg from_term to_term scrutinee in
let branches' = map explore_branch branches in
pack (Tv_Match scrutinee' ret_opt branches')
| Tv_AscribedT e ty tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
let ty' = replace_term_in dbg from_term to_term ty in
pack (Tv_AscribedT e' ty' tac use_eq)
| Tv_AscribedC e c tac use_eq ->
let e' = replace_term_in dbg from_term to_term e in
pack (Tv_AscribedC e' c tac use_eq)
| _ ->
(* Unknown *)
tm
val strip_implicit_parameters : term -> Tac term
let rec strip_implicit_parameters tm =
match inspect tm with
| Tv_App hd (a,qualif) ->
if Q_Implicit? qualif then strip_implicit_parameters hd else tm
| _ -> tm
val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit | false | false | FStar.InteractiveHelpers.PostProcess.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 15,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val unfold_in_assert_or_assume : bool -> exploration_result term -> Tac unit | [] | FStar.InteractiveHelpers.PostProcess.unfold_in_assert_or_assume | {
"file_name": "ulib/experimental/FStar.InteractiveHelpers.PostProcess.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
dbg: Prims.bool ->
ares: FStar.InteractiveHelpers.PostProcess.exploration_result FStar.Reflection.Types.term
-> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 30,
"end_line": 737,
"start_col": 2,
"start_line": 603
} |
Prims.Tot | val disjoint_locations (l1 l2: locations) : pbool | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1 | val disjoint_locations (l1 l2: locations) : pbool
let disjoint_locations (l1 l2: locations) : pbool = | false | null | false | for_all (fun x -> disjoint_location_from_locations x l2) l1 | {
"checked_file": "Vale.Transformers.Locations.fsti.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
"total"
] | [
"Vale.Transformers.Locations.locations",
"Vale.Def.PossiblyMonad.for_all",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Vale.Def.PossiblyMonad.pbool"
] | [] | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *) | false | true | Vale.Transformers.Locations.fsti | {
"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"
} | null | val disjoint_locations (l1 l2: locations) : pbool | [] | Vale.Transformers.Locations.disjoint_locations | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | l1: Vale.Transformers.Locations.locations -> l2: Vale.Transformers.Locations.locations
-> Vale.Def.PossiblyMonad.pbool | {
"end_col": 6,
"end_line": 42,
"start_col": 2,
"start_line": 40
} |
Prims.Tot | val disjoint_location_from_locations (a: location) (l: locations) : pbool | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l | val disjoint_location_from_locations (a: location) (l: locations) : pbool
let disjoint_location_from_locations (a: location) (l: locations) : pbool = | false | null | false | for_all (fun b -> disjoint_location a b) l | {
"checked_file": "Vale.Transformers.Locations.fsti.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
"total"
] | [
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.locations",
"Vale.Def.PossiblyMonad.for_all",
"Vale.Transformers.Locations.disjoint_location",
"Vale.Def.PossiblyMonad.pbool"
] | [] | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *) | false | true | Vale.Transformers.Locations.fsti | {
"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"
} | null | val disjoint_location_from_locations (a: location) (l: locations) : pbool | [] | Vale.Transformers.Locations.disjoint_location_from_locations | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Vale.Transformers.Locations.location -> l: Vale.Transformers.Locations.locations
-> Vale.Def.PossiblyMonad.pbool | {
"end_col": 7,
"end_line": 36,
"start_col": 2,
"start_line": 34
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let location_eq = l:location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)} | let location_eq = | false | null | false | l: location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)} | {
"checked_file": "Vale.Transformers.Locations.fsti.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
"total"
] | [
"Vale.Transformers.Locations.location",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"FStar.Universe.raise_t",
"Vale.Transformers.Locations.location_val_eqt"
] | [] | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *)
let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1
(** [disjoint_locations] is symmetric *)
let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] ->
lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys
(** Inversion lemma based on FStar.Universe.downgrade_val_raise_val, with more liberal SMTPat *)
val downgrade_val_raise_val_u0_u1 :
#a:Type0 ->
x:a ->
Lemma
(ensures FStar.Universe.downgrade_val u#0 u#1 (FStar.Universe.raise_val x) == x)
[SMTPat (FStar.Universe.raise_val x)]
(** [location_val_t a] is the type of the value represented by the location [a]. *)
val location_val_t : location -> Type u#1
(** Same as location_val_t in cases where location_val_t is an eqtype, otherwise arbitrary *)
val location_val_eqt : location -> eqtype | false | true | Vale.Transformers.Locations.fsti | {
"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"
} | null | val location_eq : Type0 | [] | Vale.Transformers.Locations.location_eq | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 93,
"end_line": 74,
"start_col": 18,
"start_line": 74
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let filter_state (s:machine_state) (flags:flags_t) (ok:bool) (trace:list observation) =
{ s with
ms_flags = FunctionalExtensionality.on_dom flag
(fun f ->
if f = fCarry then
s.ms_flags fCarry
else if f = fOverflow then
s.ms_flags fOverflow
else
flags f ) ;
ms_ok = ok ;
ms_trace = trace } | let filter_state (s: machine_state) (flags: flags_t) (ok: bool) (trace: list observation) = | false | null | false | {
s with
ms_flags
=
FunctionalExtensionality.on_dom flag
(fun f ->
if f = fCarry
then s.ms_flags fCarry
else if f = fOverflow then s.ms_flags fOverflow else flags f);
ms_ok = ok;
ms_trace = trace
} | {
"checked_file": "Vale.Transformers.Locations.fsti.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
"total"
] | [
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.flags_t",
"Prims.bool",
"Prims.list",
"Vale.X64.Machine_s.observation",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"FStar.FunctionalExtensionality.on_dom",
"Vale.X64.Machine_s.flag",
"Vale.X64.Machine_Semantics_s.flag_val_t",
"Prims.op_Equality",
"Vale.X64.Machine_s.fCarry",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_s.fOverflow",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint"
] | [] | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *)
let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1
(** [disjoint_locations] is symmetric *)
let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] ->
lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys
(** Inversion lemma based on FStar.Universe.downgrade_val_raise_val, with more liberal SMTPat *)
val downgrade_val_raise_val_u0_u1 :
#a:Type0 ->
x:a ->
Lemma
(ensures FStar.Universe.downgrade_val u#0 u#1 (FStar.Universe.raise_val x) == x)
[SMTPat (FStar.Universe.raise_val x)]
(** [location_val_t a] is the type of the value represented by the location [a]. *)
val location_val_t : location -> Type u#1
(** Same as location_val_t in cases where location_val_t is an eqtype, otherwise arbitrary *)
val location_val_eqt : location -> eqtype
(** Locations where location_val_t is an eqtype *)
let location_eq = l:location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)}
(** Coerce location_val_eqt to location_val_t *)
let raise_location_val_eqt (#l:location_eq) (v:location_val_eqt l) : location_val_t l =
coerce (FStar.Universe.raise_val v)
(** [eval_location a s] gives the value at location [a] in state [s]. *)
val eval_location :
a:location ->
machine_state ->
location_val_t a
(** [update_location a v s0] gives a new state with location [a] updated to [v]. *)
val update_location :
a:location ->
v:location_val_t a ->
machine_state ->
s:machine_state{eval_location a s == v}
(** Updating one location does not affect a different location. *)
val lemma_locations_truly_disjoint :
a:location ->
a_change:location ->
v:location_val_t a_change ->
s:machine_state ->
Lemma
(requires (a <> a_change))
(ensures (eval_location a s == eval_location a (update_location a_change v s)))
(** Filter out things we don't want to compare on two states *) | false | true | Vale.Transformers.Locations.fsti | {
"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"
} | null | val filter_state : s: Vale.X64.Machine_Semantics_s.machine_state ->
flags: Vale.X64.Machine_Semantics_s.flags_t ->
ok: Prims.bool ->
trace: Prims.list Vale.X64.Machine_s.observation
-> Vale.X64.Machine_Semantics_s.machine_state | [] | Vale.Transformers.Locations.filter_state | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
s: Vale.X64.Machine_Semantics_s.machine_state ->
flags: Vale.X64.Machine_Semantics_s.flags_t ->
ok: Prims.bool ->
trace: Prims.list Vale.X64.Machine_s.observation
-> Vale.X64.Machine_Semantics_s.machine_state | {
"end_col": 20,
"end_line": 115,
"start_col": 4,
"start_line": 105
} |
|
Prims.Tot | val raise_location_val_eqt (#l: location_eq) (v: location_val_eqt l) : location_val_t l | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let raise_location_val_eqt (#l:location_eq) (v:location_val_eqt l) : location_val_t l =
coerce (FStar.Universe.raise_val v) | val raise_location_val_eqt (#l: location_eq) (v: location_val_eqt l) : location_val_t l
let raise_location_val_eqt (#l: location_eq) (v: location_val_eqt l) : location_val_t l = | false | null | false | coerce (FStar.Universe.raise_val v) | {
"checked_file": "Vale.Transformers.Locations.fsti.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
"total"
] | [
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.Locations.location_val_eqt",
"Vale.X64.Instruction_s.coerce",
"Vale.Transformers.Locations.location_val_t",
"FStar.Universe.raise_t",
"FStar.Universe.raise_val"
] | [] | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *)
let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1
(** [disjoint_locations] is symmetric *)
let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] ->
lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys
(** Inversion lemma based on FStar.Universe.downgrade_val_raise_val, with more liberal SMTPat *)
val downgrade_val_raise_val_u0_u1 :
#a:Type0 ->
x:a ->
Lemma
(ensures FStar.Universe.downgrade_val u#0 u#1 (FStar.Universe.raise_val x) == x)
[SMTPat (FStar.Universe.raise_val x)]
(** [location_val_t a] is the type of the value represented by the location [a]. *)
val location_val_t : location -> Type u#1
(** Same as location_val_t in cases where location_val_t is an eqtype, otherwise arbitrary *)
val location_val_eqt : location -> eqtype
(** Locations where location_val_t is an eqtype *)
let location_eq = l:location{location_val_t l == FStar.Universe.raise_t (location_val_eqt l)}
(** Coerce location_val_eqt to location_val_t *) | false | false | Vale.Transformers.Locations.fsti | {
"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"
} | null | val raise_location_val_eqt (#l: location_eq) (v: location_val_eqt l) : location_val_t l | [] | Vale.Transformers.Locations.raise_location_val_eqt | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | v: Vale.Transformers.Locations.location_val_eqt l -> Vale.Transformers.Locations.location_val_t l | {
"end_col": 37,
"end_line": 78,
"start_col": 2,
"start_line": 78
} |
FStar.Pervasives.Lemma | val lemma_disjoint_locations_symmetric (l1 l2: _)
: Lemma (ensures ((!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) =
match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] ->
lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys | val lemma_disjoint_locations_symmetric (l1 l2: _)
: Lemma (ensures ((!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2])
let rec lemma_disjoint_locations_symmetric l1 l2
: Lemma (ensures ((!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) = | false | null | true | match l1, l2 with
| [], [] -> ()
| [], x :: xs | x :: xs, [] -> lemma_disjoint_locations_symmetric xs []
| x :: xs, y :: ys ->
lemma_disjoint_locations_symmetric l1 ys;
lemma_disjoint_locations_symmetric xs l2;
lemma_disjoint_locations_symmetric xs ys | {
"checked_file": "Vale.Transformers.Locations.fsti.checked",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Locations.fsti"
} | [
"lemma",
""
] | [
"Vale.Transformers.Locations.locations",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.lemma_disjoint_locations_symmetric",
"Prims.Nil",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_locations",
"FStar.Pervasives.pattern"
] | [] | module Vale.Transformers.Locations
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
module L = FStar.List.Tot
(** An [location] is a portion of the [machine_state] that may be
independently modified and/or accessed. *)
val location : eqtype
unfold
type locations = list location
(** [disjoint_location a1 a2] is true whenever locations [a1] and [a2]
are disjoint. When not disjoint, it gives a reason for why not. *)
val disjoint_location : location -> location -> pbool
(** Disjointness is the same as syntactic equality on the locations. *)
val auto_lemma_disjoint_location :
a1:location -> a2:location ->
Lemma
(ensures (!!(disjoint_location a1 a2) = (a1 <> a2)))
[SMTPat (!!(disjoint_location a1 a2))]
(** Disjointness of a [location] from [locations] *)
let disjoint_location_from_locations (a:location) (l:locations) : pbool =
for_all (fun b ->
disjoint_location a b
) l
(** Disjointness of [locations] *)
let disjoint_locations (l1 l2:locations) : pbool =
for_all (fun x ->
disjoint_location_from_locations x l2
) l1
(** [disjoint_locations] is symmetric *)
let rec lemma_disjoint_locations_symmetric l1 l2 :
Lemma
(ensures (
(!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1)))) | false | false | Vale.Transformers.Locations.fsti | {
"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"
} | null | val lemma_disjoint_locations_symmetric (l1 l2: _)
: Lemma (ensures ((!!(disjoint_locations l1 l2) = !!(disjoint_locations l2 l1))))
(decreases %[L.length l1 + L.length l2]) | [
"recursion"
] | Vale.Transformers.Locations.lemma_disjoint_locations_symmetric | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Locations.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | l1: Vale.Transformers.Locations.locations -> l2: Vale.Transformers.Locations.locations
-> FStar.Pervasives.Lemma
(ensures
!!(Vale.Transformers.Locations.disjoint_locations l1 l2) =
!!(Vale.Transformers.Locations.disjoint_locations l2 l1))
(decreases FStar.List.Tot.Base.length l1 + FStar.List.Tot.Base.length l2) | {
"end_col": 44,
"end_line": 57,
"start_col": 2,
"start_line": 50
} |
Prims.Tot | val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"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
}
] | false | let parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
= parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k;
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p) | val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
let parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t) = | false | null | false | parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k;
and_then #_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p) | {
"checked_file": "LowParse.Spec.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.VLData.fst"
} | [
"total"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Combinators.and_then",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.VLData.parse_vldata_payload",
"Prims.unit",
"LowParse.Spec.VLData.parse_vldata_gen_kind_correct",
"LowParse.Spec.VLData.parse_fldata_and_then_cases_injective",
"LowParse.Spec.VLData.parse_vldata_gen_kind"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t) | false | false | LowParse.Spec.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 64,
"max_ifuel": 64,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t) | [] | LowParse.Spec.VLData.parse_vldata_gen | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t
-> LowParse.Spec.Base.parser (LowParse.Spec.VLData.parse_vldata_gen_kind sz k) t | {
"end_col": 33,
"end_line": 26,
"start_col": 2,
"start_line": 18
} |
FStar.Pervasives.Lemma | val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p)) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"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
}
] | false | let parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
= parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k | val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k ==
and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz))
(parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then #_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p)) = | false | null | true | parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k | {
"checked_file": "LowParse.Spec.VLData.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.VLData.fst"
} | [
"lemma"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.VLData.parse_vldata_gen_kind_correct",
"Prims.unit",
"LowParse.Spec.VLData.parse_fldata_and_then_cases_injective",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.and_then_cases_injective",
"Prims.eq2",
"LowParse.Spec.VLData.parse_vldata_payload",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.VLData.parse_vldata_gen",
"LowParse.Spec.Combinators.and_then",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
= parse_fldata_and_then_cases_injective sz f p;
parse_vldata_gen_kind_correct sz k;
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p)
let parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t | false | false | LowParse.Spec.VLData.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 64,
"max_ifuel": 64,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": true,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p)) | [] | LowParse.Spec.VLData.parse_vldata_gen_eq_def | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.and_then_cases_injective (LowParse.Spec.VLData.parse_vldata_payload sz
f
p) /\
LowParse.Spec.VLData.parse_vldata_gen_kind sz k ==
LowParse.Spec.Combinators.and_then_kind (LowParse.Spec.Combinators.parse_filter_kind (LowParse.Spec.BoundedInt.parse_bounded_integer_kind
sz))
(LowParse.Spec.VLData.parse_vldata_payload_kind sz k) /\
LowParse.Spec.VLData.parse_vldata_gen sz f p ==
LowParse.Spec.Combinators.and_then (LowParse.Spec.Combinators.parse_filter (LowParse.Spec.BoundedInt.parse_bounded_integer
sz)
f)
(LowParse.Spec.VLData.parse_vldata_payload sz f p)) | {
"end_col": 36,
"end_line": 46,
"start_col": 2,
"start_line": 45
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let concrete_xkey (i: impl) = Lib.ByteSequence.lbytes (concrete_xkey_length i) | let concrete_xkey (i: impl) = | false | null | false | Lib.ByteSequence.lbytes (concrete_xkey_length i) | {
"checked_file": "Spec.Cipher.Expansion.fsti.checked",
"dependencies": [
"Spec.Agile.Cipher.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Cipher.Expansion.fsti"
} | [
"total"
] | [
"Spec.Cipher.Expansion.impl",
"Lib.ByteSequence.lbytes",
"Spec.Cipher.Expansion.concrete_xkey_length"
] | [] | module Spec.Cipher.Expansion
open Spec.Agile.Cipher
/// This module gathers key expansion details shared between the CTR and AEAD
/// constructions.
///
/// From the perspective of Spec.Agile.CTR (and EverCrypt.CTR) and Spec.Agile.AEAD
/// (and EverCrypt.AEAD), none of the following appear in the interface:
///
/// - expanded keys, considered to be an implementation detail
/// - concrete representation of expanded keys used by Vale, which has more
/// precomputed things stored beyond the expanded key.
///
/// The interface remains until we get rid of ``friend Lib.IntTypes``.
/// This type is used at run-time by both ``EverCrypt.CTR`` and
/// ``EverCrypt.AEAD`` -- we assume that an implementation covers both CTR and
/// AEAD. It lists valid combinations, and serves as an index for concrete
/// expanded keys, which include provider-specific representation choices. This
/// type serves several purposes.
type impl =
| Hacl_CHACHA20
| Vale_AES128
| Vale_AES256
let cipher_alg_of_impl (i: impl): cipher_alg =
match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256
/// Length of an expanded key per the AES specification.
val xkey_length (a: cipher_alg): Lib.IntTypes.size_nat
let xkey a = Lib.ByteSequence.lbytes (xkey_length a)
/// Length of the concrete representation of an expanded key, for a given implementation.
val concrete_xkey_length (i: impl): Lib.IntTypes.size_nat | false | true | Spec.Cipher.Expansion.fsti | {
"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"
} | null | val concrete_xkey : i: Spec.Cipher.Expansion.impl -> Type0 | [] | Spec.Cipher.Expansion.concrete_xkey | {
"file_name": "specs/Spec.Cipher.Expansion.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | i: Spec.Cipher.Expansion.impl -> Type0 | {
"end_col": 78,
"end_line": 41,
"start_col": 30,
"start_line": 41
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let xkey a = Lib.ByteSequence.lbytes (xkey_length a) | let xkey a = | false | null | false | Lib.ByteSequence.lbytes (xkey_length a) | {
"checked_file": "Spec.Cipher.Expansion.fsti.checked",
"dependencies": [
"Spec.Agile.Cipher.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Cipher.Expansion.fsti"
} | [
"total"
] | [
"Spec.Agile.Cipher.cipher_alg",
"Lib.ByteSequence.lbytes",
"Spec.Cipher.Expansion.xkey_length"
] | [] | module Spec.Cipher.Expansion
open Spec.Agile.Cipher
/// This module gathers key expansion details shared between the CTR and AEAD
/// constructions.
///
/// From the perspective of Spec.Agile.CTR (and EverCrypt.CTR) and Spec.Agile.AEAD
/// (and EverCrypt.AEAD), none of the following appear in the interface:
///
/// - expanded keys, considered to be an implementation detail
/// - concrete representation of expanded keys used by Vale, which has more
/// precomputed things stored beyond the expanded key.
///
/// The interface remains until we get rid of ``friend Lib.IntTypes``.
/// This type is used at run-time by both ``EverCrypt.CTR`` and
/// ``EverCrypt.AEAD`` -- we assume that an implementation covers both CTR and
/// AEAD. It lists valid combinations, and serves as an index for concrete
/// expanded keys, which include provider-specific representation choices. This
/// type serves several purposes.
type impl =
| Hacl_CHACHA20
| Vale_AES128
| Vale_AES256
let cipher_alg_of_impl (i: impl): cipher_alg =
match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256
/// Length of an expanded key per the AES specification.
val xkey_length (a: cipher_alg): Lib.IntTypes.size_nat | false | true | Spec.Cipher.Expansion.fsti | {
"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"
} | null | val xkey : a: Spec.Agile.Cipher.cipher_alg -> Type0 | [] | Spec.Cipher.Expansion.xkey | {
"file_name": "specs/Spec.Cipher.Expansion.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Agile.Cipher.cipher_alg -> Type0 | {
"end_col": 52,
"end_line": 36,
"start_col": 13,
"start_line": 36
} |
|
Prims.Tot | val cipher_alg_of_impl (i: impl) : cipher_alg | [
{
"abbrev": false,
"full_module": "Spec.Agile.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cipher_alg_of_impl (i: impl): cipher_alg =
match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256 | val cipher_alg_of_impl (i: impl) : cipher_alg
let cipher_alg_of_impl (i: impl) : cipher_alg = | false | null | false | match i with
| Hacl_CHACHA20 -> CHACHA20
| Vale_AES128 -> AES128
| Vale_AES256 -> AES256 | {
"checked_file": "Spec.Cipher.Expansion.fsti.checked",
"dependencies": [
"Spec.Agile.Cipher.fsti.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Cipher.Expansion.fsti"
} | [
"total"
] | [
"Spec.Cipher.Expansion.impl",
"Spec.Agile.Cipher.CHACHA20",
"Spec.Agile.Cipher.AES128",
"Spec.Agile.Cipher.AES256",
"Spec.Agile.Cipher.cipher_alg"
] | [] | module Spec.Cipher.Expansion
open Spec.Agile.Cipher
/// This module gathers key expansion details shared between the CTR and AEAD
/// constructions.
///
/// From the perspective of Spec.Agile.CTR (and EverCrypt.CTR) and Spec.Agile.AEAD
/// (and EverCrypt.AEAD), none of the following appear in the interface:
///
/// - expanded keys, considered to be an implementation detail
/// - concrete representation of expanded keys used by Vale, which has more
/// precomputed things stored beyond the expanded key.
///
/// The interface remains until we get rid of ``friend Lib.IntTypes``.
/// This type is used at run-time by both ``EverCrypt.CTR`` and
/// ``EverCrypt.AEAD`` -- we assume that an implementation covers both CTR and
/// AEAD. It lists valid combinations, and serves as an index for concrete
/// expanded keys, which include provider-specific representation choices. This
/// type serves several purposes.
type impl =
| Hacl_CHACHA20
| Vale_AES128
| Vale_AES256 | false | true | Spec.Cipher.Expansion.fsti | {
"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"
} | null | val cipher_alg_of_impl (i: impl) : cipher_alg | [] | Spec.Cipher.Expansion.cipher_alg_of_impl | {
"file_name": "specs/Spec.Cipher.Expansion.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | i: Spec.Cipher.Expansion.impl -> Spec.Agile.Cipher.cipher_alg | {
"end_col": 25,
"end_line": 31,
"start_col": 2,
"start_line": 28
} |
Prims.Tot | val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f)) | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
gaccessor_prop_equiv (parse_synth p1 f) p1 (clens_synth g f) (gaccessor_synth' p1 f g u);
gaccessor_synth' p1 f g u | val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
let gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f)) = | false | null | false | synth_injective_synth_inverse_synth_inverse_recip f g ();
gaccessor_prop_equiv (parse_synth p1 f) p1 (clens_synth g f) (gaccessor_synth' p1 f g u);
gaccessor_synth' p1 f g u | {
"checked_file": "LowParse.Low.Combinators.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Combinators.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Low.Combinators.gaccessor_synth'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth",
"LowParse.Spec.Combinators.synth_injective_synth_inverse_synth_inverse_recip",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
#set-options "--z3rlimit 16"
let gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f)) | false | false | LowParse.Low.Combinators.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f)) | [] | LowParse.Low.Combinators.gaccessor_synth | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u213:
Prims.squash (LowParse.Spec.Combinators.synth_inverse f g /\
LowParse.Spec.Combinators.synth_injective f)
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Combinators.parse_synth p1 f)
p1
(LowParse.Low.Combinators.clens_synth g f) | {
"end_col": 27,
"end_line": 26,
"start_col": 2,
"start_line": 24
} |
Prims.Tot | val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f)) | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
= gaccessor_prop_equiv p1 (parse_synth p1 f) (clens_synth_inv g f) (gaccessor_synth_inv' p1 f g u);
gaccessor_synth_inv' p1 f g u | val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
let gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f)) = | false | null | false | gaccessor_prop_equiv p1 (parse_synth p1 f) (clens_synth_inv g f) (gaccessor_synth_inv' p1 f g u);
gaccessor_synth_inv' p1 f g u | {
"checked_file": "LowParse.Low.Combinators.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Combinators.fst"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Low.Combinators.gaccessor_synth_inv'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth_inv",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
#set-options "--z3rlimit 16"
let gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
gaccessor_prop_equiv (parse_synth p1 f) p1 (clens_synth g f) (gaccessor_synth' p1 f g u);
gaccessor_synth' p1 f g u
let gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
= ()
let gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f)) | false | false | LowParse.Low.Combinators.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f)) | [] | LowParse.Low.Combinators.gaccessor_synth_inv | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u247:
Prims.squash (LowParse.Spec.Combinators.synth_inverse f g /\
LowParse.Spec.Combinators.synth_injective f)
-> LowParse.Low.Base.Spec.gaccessor p1
(LowParse.Spec.Combinators.parse_synth p1 f)
(LowParse.Low.Combinators.clens_synth_inv g f) | {
"end_col": 31,
"end_line": 51,
"start_col": 2,
"start_line": 50
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Poly1305",
"short_module": "Poly"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20Poly1305",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let poly1305_padded_st (w:field_spec) =
ctx:Poly.poly1305_ctx w
-> len:size_t
-> text:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h ctx /\ live h text /\ disjoint ctx text /\
Poly.state_inv_t h ctx)
(ensures fun h0 _ h1 ->
modifies (loc ctx) h0 h1 /\
Poly.state_inv_t h1 ctx /\
Poly.as_get_r h0 ctx == Poly.as_get_r h1 ctx /\
Poly.as_get_acc h1 ctx ==
Spec.poly1305_padded (Poly.as_get_r h0 ctx) (as_seq h0 text) (Poly.as_get_acc h0 ctx)) | let poly1305_padded_st (w: field_spec) = | false | null | false | ctx: Poly.poly1305_ctx w -> len: size_t -> text: lbuffer uint8 len
-> Stack unit
(requires fun h -> live h ctx /\ live h text /\ disjoint ctx text /\ Poly.state_inv_t h ctx)
(ensures
fun h0 _ h1 ->
modifies (loc ctx) h0 h1 /\ Poly.state_inv_t h1 ctx /\
Poly.as_get_r h0 ctx == Poly.as_get_r h1 ctx /\
Poly.as_get_acc h1 ctx ==
Spec.poly1305_padded (Poly.as_get_r h0 ctx) (as_seq h0 text) (Poly.as_get_acc h0 ctx)) | {
"checked_file": "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked",
"dependencies": [
"Spec.Chacha20Poly1305.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20Poly1305.PolyCore.fst"
} | [
"total"
] | [
"Hacl.Impl.Poly1305.Fields.field_spec",
"Hacl.Impl.Poly1305.poly1305_ctx",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Poly1305.Fields.limb",
"Lib.Buffer.disjoint",
"Hacl.Impl.Poly1305.state_inv_t",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Poly1305.felem",
"Hacl.Impl.Poly1305.as_get_r",
"Hacl.Impl.Poly1305.as_get_acc",
"Spec.Chacha20Poly1305.poly1305_padded",
"Lib.Buffer.as_seq"
] | [] | module Hacl.Impl.Chacha20Poly1305.PolyCore
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Poly1305.Fields
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20Poly1305
module Poly = Hacl.Impl.Poly1305
#set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 1 --record_options"
inline_for_extraction noextract | false | true | Hacl.Impl.Chacha20Poly1305.PolyCore.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly1305_padded_st : w: Hacl.Impl.Poly1305.Fields.field_spec -> Type0 | [] | Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st | {
"file_name": "code/chacha20poly1305/Hacl.Impl.Chacha20Poly1305.PolyCore.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | w: Hacl.Impl.Poly1305.Fields.field_spec -> Type0 | {
"end_col": 92,
"end_line": 33,
"start_col": 4,
"start_line": 21
} |
|
Prims.Tot | val poly1305_padded: #w:field_spec -> poly1305_padded_st w | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Poly1305",
"short_module": "Poly"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20Poly1305",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let poly1305_padded #w ctx len text =
let h0 = ST.get () in
push_frame ();
let h1 = ST.get () in
Poly.reveal_ctx_inv ctx h0 h1;
let n = len /. 16ul in
let r = len %. 16ul in
let blocks = sub text 0ul (n *! 16ul) in
let rem = sub text (n *! 16ul) r in // the extra part of the input data
Poly.poly1305_update #w ctx (n *! 16ul) blocks;
let h2 = ST.get () in
let tmp = create 16ul (u8 0) in
update_sub tmp 0ul r rem;
let h3 = ST.get() in
Poly.reveal_ctx_inv ctx h2 h3;
if r >. 0ul then
Poly.poly1305_update1 ctx tmp;
let h4 = ST.get () in
pop_frame();
let h5 = ST.get () in
Poly.reveal_ctx_inv ctx h4 h5 | val poly1305_padded: #w:field_spec -> poly1305_padded_st w
let poly1305_padded #w ctx len text = | false | null | false | let h0 = ST.get () in
push_frame ();
let h1 = ST.get () in
Poly.reveal_ctx_inv ctx h0 h1;
let n = len /. 16ul in
let r = len %. 16ul in
let blocks = sub text 0ul (n *! 16ul) in
let rem = sub text (n *! 16ul) r in
Poly.poly1305_update #w ctx (n *! 16ul) blocks;
let h2 = ST.get () in
let tmp = create 16ul (u8 0) in
update_sub tmp 0ul r rem;
let h3 = ST.get () in
Poly.reveal_ctx_inv ctx h2 h3;
if r >. 0ul then Poly.poly1305_update1 ctx tmp;
let h4 = ST.get () in
pop_frame ();
let h5 = ST.get () in
Poly.reveal_ctx_inv ctx h4 h5 | {
"checked_file": "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked",
"dependencies": [
"Spec.Chacha20Poly1305.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20Poly1305.PolyCore.fst"
} | [
"total"
] | [
"Hacl.Impl.Poly1305.Fields.field_spec",
"Hacl.Impl.Poly1305.poly1305_ctx",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.Poly1305.reveal_ctx_inv",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.pop_frame",
"Lib.IntTypes.op_Greater_Dot",
"Lib.IntTypes.U32",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Poly1305.poly1305_update1",
"Prims.bool",
"Lib.Buffer.update_sub",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Hacl.Impl.Poly1305.poly1305_update",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.PUB",
"Lib.Buffer.sub",
"Lib.IntTypes.mul",
"Lib.IntTypes.op_Percent_Dot",
"Lib.IntTypes.op_Slash_Dot",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Chacha20Poly1305.PolyCore
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Poly1305.Fields
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20Poly1305
module Poly = Hacl.Impl.Poly1305
#set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 1 --record_options"
inline_for_extraction noextract
let poly1305_padded_st (w:field_spec) =
ctx:Poly.poly1305_ctx w
-> len:size_t
-> text:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h ctx /\ live h text /\ disjoint ctx text /\
Poly.state_inv_t h ctx)
(ensures fun h0 _ h1 ->
modifies (loc ctx) h0 h1 /\
Poly.state_inv_t h1 ctx /\
Poly.as_get_r h0 ctx == Poly.as_get_r h1 ctx /\
Poly.as_get_acc h1 ctx ==
Spec.poly1305_padded (Poly.as_get_r h0 ctx) (as_seq h0 text) (Poly.as_get_acc h0 ctx))
inline_for_extraction noextract
val poly1305_padded: #w:field_spec -> poly1305_padded_st w | false | false | Hacl.Impl.Chacha20Poly1305.PolyCore.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly1305_padded: #w:field_spec -> poly1305_padded_st w | [] | Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded | {
"file_name": "code/chacha20poly1305/Hacl.Impl.Chacha20Poly1305.PolyCore.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st w | {
"end_col": 31,
"end_line": 59,
"start_col": 37,
"start_line": 39
} |
Prims.Tot | val valid_addr128 (ptr: int) (mem: S.machine_heap) : bool | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem | val valid_addr128 (ptr: int) (mem: S.machine_heap) : bool
let valid_addr128 (ptr: int) (mem: S.machine_heap) : bool = | false | null | false | valid_addr32 (ptr + 0) mem && valid_addr32 (ptr + 4) mem && valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Prims.int",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.op_AmpAmp",
"Vale.X64.Leakage_Ins.valid_addr32",
"Prims.op_Addition",
"Prims.bool"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0 | false | true | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_addr128 (ptr: int) (mem: S.machine_heap) : bool | [] | Vale.X64.Leakage_Ins.valid_addr128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> mem: Vale.Arch.MachineHeap_s.machine_heap -> Prims.bool | {
"end_col": 29,
"end_line": 342,
"start_col": 2,
"start_line": 339
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let obs_args = S.obs_args | let obs_args = | false | null | false | S.obs_args | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Machine_Semantics_s.obs_args"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd | false | false | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val obs_args : args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | [] | Vale.X64.Leakage_Ins.obs_args | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | {
"end_col": 32,
"end_line": 15,
"start_col": 22,
"start_line": 15
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let obs_inouts = S.obs_inouts | let obs_inouts = | false | null | false | S.obs_inouts | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Machine_Semantics_s.obs_inouts"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd | false | false | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val obs_inouts : inouts: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t inouts args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | [] | Vale.X64.Leakage_Ins.obs_inouts | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
inouts: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t inouts args ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.list Vale.X64.Machine_s.observation | {
"end_col": 36,
"end_line": 16,
"start_col": 24,
"start_line": 16
} |
|
Prims.Tot | val update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (i: int) : Vale.Def.Types_s.nat8 | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0 | val update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (i: int) : Vale.Def.Types_s.nat8
let update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (i: int) : Vale.Def.Types_s.nat8 = | false | null | false | let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4
then update_heap32_val (ptr + 0) v.lo0 i
else
if 4 <= j && j < 8
then update_heap32_val (ptr + 4) v.lo1 i
else
if 8 <= j && j < 12
then update_heap32_val (ptr + 8) v.hi2 i
else if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else 0 | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Vale.X64.Leakage_Ins.update_heap32_val",
"Prims.op_Addition",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Prims.bool",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat8",
"Prims.op_Subtraction"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"] | false | true | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (i: int) : Vale.Def.Types_s.nat8 | [] | Vale.X64.Leakage_Ins.update_heap128_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> i: Prims.int -> Vale.Def.Types_s.nat8 | {
"end_col": 3,
"end_line": 336,
"start_col": 2,
"start_line": 330
} |
Prims.Tot | val valid_addr32 (ptr: int) (mem: S.machine_heap) : bool | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem | val valid_addr32 (ptr: int) (mem: S.machine_heap) : bool
let valid_addr32 (ptr: int) (mem: S.machine_heap) : bool = | false | null | false | S.valid_addr (ptr + 0) mem && S.valid_addr (ptr + 1) mem && S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Prims.int",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.op_AmpAmp",
"Vale.Arch.MachineHeap_s.valid_addr",
"Prims.op_Addition",
"Prims.bool"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0 | false | true | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_addr32 (ptr: int) (mem: S.machine_heap) : bool | [] | Vale.X64.Leakage_Ins.valid_addr32 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> mem: Vale.Arch.MachineHeap_s.machine_heap -> Prims.bool | {
"end_col": 28,
"end_line": 270,
"start_col": 2,
"start_line": 267
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let machine_eval_code = S.machine_eval_code | let machine_eval_code = | false | null | false | S.machine_eval_code | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total",
""
] | [
"Vale.X64.Machine_Semantics_s.machine_eval_code"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args | false | true | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val machine_eval_code : c: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.Tot (FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state) | [] | Vale.X64.Leakage_Ins.machine_eval_code | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Vale.X64.Machine_Semantics_s.code ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.Tot (FStar.Pervasives.Native.option Vale.X64.Machine_Semantics_s.machine_state) | {
"end_col": 50,
"end_line": 17,
"start_col": 31,
"start_line": 17
} |
|
Prims.Tot | val coerce_to_normal (#a: Type0) (x: a) : y: (normal a){x == y} | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x | val coerce_to_normal (#a: Type0) (x: a) : y: (normal a){x == y}
let coerce_to_normal (#a: Type0) (x: a) : y: (normal a){x == y} = | false | null | false | x | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Instruction_s.normal",
"Prims.eq2"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val coerce_to_normal (#a: Type0) (x: a) : y: (normal a){x == y} | [] | Vale.X64.Leakage_Ins.coerce_to_normal | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: a -> y: Vale.X64.Instruction_s.normal a {x == y} | {
"end_col": 64,
"end_line": 520,
"start_col": 63,
"start_line": 520
} |
FStar.Pervasives.Lemma | val reveal_machine_eval_code_ins (i: S.ins) (s: S.machine_state)
: Lemma (requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)] | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins | val reveal_machine_eval_code_ins (i: S.ins) (s: S.machine_state)
: Lemma (requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
let reveal_machine_eval_code_ins (i: S.ins) (s: S.machine_state)
: Lemma (requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)] = | false | null | true | reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.reveal_opaque",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Machine_Semantics_s.machine_eval_code_ins_def",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)] | false | false | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val reveal_machine_eval_code_ins (i: S.ins) (s: S.machine_state)
: Lemma (requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)] | [] | Vale.X64.Leakage_Ins.reveal_machine_eval_code_ins | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | i: Vale.X64.Machine_Semantics_s.ins -> s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Machine_Semantics_s.machine_eval_code_ins i s ==
Vale.X64.Machine_Semantics_s.machine_eval_code_ins_def i s)
[SMTPat (Vale.X64.Machine_Semantics_s.machine_eval_code_ins i s)] | {
"end_col": 67,
"end_line": 24,
"start_col": 2,
"start_line": 24
} |
Prims.Pure | val check_if_alloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts) | val check_if_alloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
let check_if_alloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts) = | false | null | false | (true, ts) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Alloc",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_alloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_alloc_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 12,
"end_line": 577,
"start_col": 2,
"start_line": 577
} |
Prims.Pure | val check_if_dealloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts) | val check_if_dealloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
let check_if_dealloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts) = | false | null | false | (true, ts) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Dealloc",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_dealloc_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 12,
"end_line": 583,
"start_col": 2,
"start_line": 583
} |
Prims.Tot | val update_heap64_val (ptr: int) (v: nat64) (i: int) : Vale.Def.Types_s.nat8 | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0 | val update_heap64_val (ptr: int) (v: nat64) (i: int) : Vale.Def.Types_s.nat8
let update_heap64_val (ptr: int) (v: nat64) (i: int) : Vale.Def.Types_s.nat8 = | false | null | false | let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0 | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Prims.int",
"Vale.X64.Machine_s.nat64",
"Prims.op_Subtraction",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat8",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words_s.__proj__Mktwo__item__hi",
"Vale.Def.Words_s.__proj__Mktwo__item__lo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"] | false | true | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_heap64_val (ptr: int) (v: nat64) (i: int) : Vale.Def.Types_s.nat8 | [] | Vale.X64.Leakage_Ins.update_heap64_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> v: Vale.X64.Machine_s.nat64 -> i: Prims.int -> Vale.Def.Types_s.nat8 | {
"end_col": 10,
"end_line": 306,
"start_col": 2,
"start_line": 291
} |
FStar.Pervasives.Lemma | val lemma_update_heap64_domain (ptr: int) (v: nat64) (mem: S.machine_heap)
: Lemma (requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))] | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem)) | val lemma_update_heap64_domain (ptr: int) (v: nat64) (mem: S.machine_heap)
: Lemma (requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
let lemma_update_heap64_domain (ptr: int) (v: nat64) (mem: S.machine_heap)
: Lemma (requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))] = | false | null | true | reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem)) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.X64.Machine_s.nat64",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims._assert",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.update_heap64",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap64_reveal",
"FStar.Pervasives.reveal_opaque",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Prims.b2t",
"Prims.squash",
"Prims.eq2",
"FStar.Set.set",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))] | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_update_heap64_domain (ptr: int) (v: nat64) (mem: S.machine_heap)
: Lemma (requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))] | [] | Vale.X64.Leakage_Ins.lemma_update_heap64_domain | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> v: Vale.X64.Machine_s.nat64 -> mem: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.Arch.MachineHeap_s.valid_addr64 ptr mem)
(ensures
FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap64 ptr v mem) == FStar.Map.domain mem)
[SMTPat (FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap64 ptr v mem))] | {
"end_col": 78,
"end_line": 326,
"start_col": 2,
"start_line": 324
} |
FStar.Pervasives.Lemma | val lemma_update_heap128_domain (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap)
: Lemma (requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)] | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem)) | val lemma_update_heap128_domain (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap)
: Lemma (requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
let lemma_update_heap128_domain (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap)
: Lemma (requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)] = | false | null | true | S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem)) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims._assert",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.update_heap128",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap128_reveal",
"Prims.b2t",
"Vale.X64.Leakage_Ins.valid_addr128",
"Prims.squash",
"Prims.eq2",
"FStar.Set.set",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)] | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_update_heap128_domain (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap)
: Lemma (requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)] | [] | Vale.X64.Leakage_Ins.lemma_update_heap128_domain | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> mem: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Leakage_Ins.valid_addr128 ptr mem)
(ensures
FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap128 ptr v mem) == FStar.Map.domain mem)
[SMTPat (Vale.Arch.MachineHeap_s.update_heap128 ptr v mem)] | {
"end_col": 79,
"end_line": 361,
"start_col": 2,
"start_line": 360
} |
FStar.Pervasives.Lemma | val lemma_update_heap32_domain (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap)
: Lemma (requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))] | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem)) | val lemma_update_heap32_domain (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap)
: Lemma (requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
let lemma_update_heap32_domain (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap)
: Lemma (requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))] = | false | null | true | S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem)) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Def.Types_s.nat32",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims._assert",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.MachineHeap_s.update_heap32",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap32_reveal",
"Prims.b2t",
"Vale.X64.Leakage_Ins.valid_addr32",
"Prims.squash",
"Prims.eq2",
"FStar.Set.set",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))] | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_update_heap32_domain (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap)
: Lemma (requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))] | [] | Vale.X64.Leakage_Ins.lemma_update_heap32_domain | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> v: Vale.Def.Types_s.nat32 -> mem: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Leakage_Ins.valid_addr32 ptr mem)
(ensures
FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap32 ptr v mem) == FStar.Map.domain mem)
[SMTPat (FStar.Map.domain (Vale.Arch.MachineHeap_s.update_heap32 ptr v mem))] | {
"end_col": 78,
"end_line": 287,
"start_col": 2,
"start_line": 286
} |
FStar.Pervasives.Lemma | val lemma_preserve_valid128 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m')) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128 | val lemma_preserve_valid128 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
let lemma_preserve_valid128 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m')) = | false | null | true | reveal_opaque (`%S.valid_addr128) S.valid_addr128 | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Prims.int",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Prims.unit",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m')) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_preserve_valid128 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m')) | [] | Vale.X64.Leakage_Ins.lemma_preserve_valid128 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Vale.Arch.MachineHeap_s.machine_heap -> m': Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires FStar.Set.equal (FStar.Map.domain m) (FStar.Map.domain m'))
(ensures
forall (i: Prims.int). {:pattern Vale.Arch.MachineHeap_s.valid_addr128 i m'}
Vale.Arch.MachineHeap_s.valid_addr128 i m ==> Vale.Arch.MachineHeap_s.valid_addr128 i m') | {
"end_col": 51,
"end_line": 375,
"start_col": 2,
"start_line": 375
} |
FStar.Pervasives.Lemma | val lemma_preserve_valid64 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m')) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64 | val lemma_preserve_valid64 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
let lemma_preserve_valid64 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m')) = | false | null | true | reveal_opaque (`%S.valid_addr64) S.valid_addr64 | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Prims.int",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr64",
"Prims.unit",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m')) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_preserve_valid64 (m m': S.machine_heap)
: Lemma (requires Set.equal (Map.domain m) (Map.domain m'))
(ensures
(forall (i: int). {:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m')) | [] | Vale.X64.Leakage_Ins.lemma_preserve_valid64 | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Vale.Arch.MachineHeap_s.machine_heap -> m': Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma (requires FStar.Set.equal (FStar.Map.domain m) (FStar.Map.domain m'))
(ensures
forall (i: Prims.int). {:pattern Vale.Arch.MachineHeap_s.valid_addr64 i m'}
Vale.Arch.MachineHeap_s.valid_addr64 i m ==> Vale.Arch.MachineHeap_s.valid_addr64 i m') | {
"end_col": 49,
"end_line": 368,
"start_col": 2,
"start_line": 368
} |
FStar.Pervasives.Lemma | val lemma_update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap128 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap128 ptr v mem).[ i ])] | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val | val lemma_update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap128 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap128 ptr v mem).[ i ])]
let lemma_update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap128 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap128 ptr v mem).[ i ])] = | false | null | true | S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Def.Types_s.quad32",
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.X64.Leakage_Ins.update_heap128_val",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap128_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Leakage_Ins.op_String_Access",
"Vale.Arch.MachineHeap_s.update_heap128",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.bool",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])] | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_update_heap128_val (ptr: int) (v: Vale.Def.Types_s.quad32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap128 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap128 ptr v mem).[ i ])] | [] | Vale.X64.Leakage_Ins.lemma_update_heap128_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ptr: Prims.int ->
v: Vale.Def.Types_s.quad32 ->
mem: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.int
-> FStar.Pervasives.Lemma
(ensures
(Vale.Arch.MachineHeap_s.update_heap128 ptr v mem).[ i ] ==
(match ptr <= i && i < ptr + 16 with
| true -> Vale.X64.Leakage_Ins.update_heap128_val ptr v i
| _ -> mem.[ i ])) [SMTPat (Vale.Arch.MachineHeap_s.update_heap128 ptr v mem).[ i ]] | {
"end_col": 57,
"end_line": 353,
"start_col": 2,
"start_line": 352
} |
FStar.Pervasives.Lemma | val lemma_update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap32 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap32 ptr v mem).[ i ])] | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val | val lemma_update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap32 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap32 ptr v mem).[ i ])]
let lemma_update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap32 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap32 ptr v mem).[ i ])] = | false | null | true | S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.Def.Types_s.nat32",
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.X64.Leakage_Ins.update_heap32_val",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap32_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Leakage_Ins.op_String_Access",
"Vale.Arch.MachineHeap_s.update_heap32",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.bool",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])] | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap32 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap32 ptr v mem).[ i ])] | [] | Vale.X64.Leakage_Ins.lemma_update_heap32_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ptr: Prims.int ->
v: Vale.Def.Types_s.nat32 ->
mem: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.int
-> FStar.Pervasives.Lemma
(ensures
(Vale.Arch.MachineHeap_s.update_heap32 ptr v mem).[ i ] ==
(match ptr <= i && i < ptr + 4 with
| true -> Vale.X64.Leakage_Ins.update_heap32_val ptr v i
| _ -> mem.[ i ])) [SMTPat (Vale.Arch.MachineHeap_s.update_heap32 ptr v mem).[ i ]] | {
"end_col": 55,
"end_line": 279,
"start_col": 2,
"start_line": 278
} |
Prims.Tot | val update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (i: int) : Vale.Def.Types_s.nat8 | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0 | val update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (i: int) : Vale.Def.Types_s.nat8
let update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (i: int) : Vale.Def.Types_s.nat8 = | false | null | false | let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0 | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Prims.int",
"Vale.Def.Types_s.nat32",
"Prims.op_Subtraction",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat8",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"] | false | true | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_heap32_val (ptr: int) (v: Vale.Def.Types_s.nat32) (i: int) : Vale.Def.Types_s.nat8 | [] | Vale.X64.Leakage_Ins.update_heap32_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ptr: Prims.int -> v: Vale.Def.Types_s.nat32 -> i: Prims.int -> Vale.Def.Types_s.nat8 | {
"end_col": 10,
"end_line": 264,
"start_col": 2,
"start_line": 256
} |
FStar.Pervasives.Lemma | val lemma_update_heap64_val (ptr: int) (v: nat64) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap64 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap64 ptr v mem).[ i ])] | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val | val lemma_update_heap64_val (ptr: int) (v: nat64) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap64 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap64 ptr v mem).[ i ])]
let lemma_update_heap64_val (ptr: int) (v: nat64) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap64 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap64 ptr v mem).[ i ])] = | false | null | true | S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.int",
"Vale.X64.Machine_s.nat64",
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.X64.Leakage_Ins.update_heap64_val",
"Prims.unit",
"Vale.Arch.MachineHeap_s.update_heap64_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.Leakage_Ins.op_String_Access",
"Vale.Arch.MachineHeap_s.update_heap64",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.bool",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])] | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_update_heap64_val (ptr: int) (v: nat64) (mem: S.machine_heap) (i: int)
: Lemma (requires True)
(ensures
(S.update_heap64 ptr v mem).[ i ] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[ i ]))
[SMTPat ((S.update_heap64 ptr v mem).[ i ])] | [] | Vale.X64.Leakage_Ins.lemma_update_heap64_val | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ptr: Prims.int ->
v: Vale.X64.Machine_s.nat64 ->
mem: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.int
-> FStar.Pervasives.Lemma
(ensures
(Vale.Arch.MachineHeap_s.update_heap64 ptr v mem).[ i ] ==
(match ptr <= i && i < ptr + 8 with
| true -> Vale.X64.Leakage_Ins.update_heap64_val ptr v i
| _ -> mem.[ i ])) [SMTPat (Vale.Arch.MachineHeap_s.update_heap64 ptr v mem).[ i ]] | {
"end_col": 55,
"end_line": 317,
"start_col": 2,
"start_line": 316
} |
Prims.Tot | val instr_set_taint_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t: taint)
: analysis_taints | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t | val instr_set_taint_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t: taint)
: analysis_taints
let instr_set_taint_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t: taint)
: analysis_taints = | false | null | false | match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.set_taint",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.operand128"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val instr_set_taint_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t: taint)
: analysis_taints | [] | Vale.X64.Leakage_Ins.instr_set_taint_explicit | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Vale.X64.Instruction_s.instr_operand_explicit ->
o: Vale.X64.Instruction_s.instr_operand_t i ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Leakage_Helpers.analysis_taints | {
"end_col": 48,
"end_line": 203,
"start_col": 2,
"start_line": 201
} |
Prims.Tot | val check_if_ins_consumes_fixed_time (ins:Vale.X64.Machine_Semantics_s.ins) (ts:analysis_taints)
: (res:(bool & analysis_taints){ins_consumes_fixed_time ins ts res}) | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts | val check_if_ins_consumes_fixed_time (ins:Vale.X64.Machine_Semantics_s.ins) (ts:analysis_taints)
: (res:(bool & analysis_taints){ins_consumes_fixed_time ins ts res})
let check_if_ins_consumes_fixed_time ins ts = | false | null | false | match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Prims.Cons",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.op64",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opFlagsCf",
"Vale.X64.Instruction_s.opFlagsOf",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.HavocFlags",
"Vale.X64.Instructions_s.ins_Xor64",
"Vale.X64.Leakage_Ins.check_if_xor_consumes_fixed_time",
"Vale.X64.Instruction_s.opXmm",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time",
"Vale.X64.Instructions_s.ins_VPxor",
"Vale.X64.Leakage_Ins.check_if_vpxor_consumes_fixed_time",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Ins.check_if_push_consumes_fixed_time",
"Vale.X64.Leakage_Ins.check_if_pop_consumes_fixed_time",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Leakage_Ins.check_if_alloc_consumes_fixed_time",
"Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk) | false | false | Vale.X64.Leakage_Ins.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 4,
"initial_ifuel": 3,
"max_fuel": 4,
"max_ifuel": 3,
"no_plugins": false,
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_ins_consumes_fixed_time (ins:Vale.X64.Machine_Semantics_s.ins) (ts:analysis_taints)
: (res:(bool & analysis_taints){ins_consumes_fixed_time ins ts res}) | [] | Vale.X64.Leakage_Ins.check_if_ins_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> res:
(Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints)
{Vale.X64.Leakage_Helpers.ins_consumes_fixed_time ins ts res} | {
"end_col": 63,
"end_line": 612,
"start_col": 2,
"start_line": 604
} |
Prims.Pure | val check_if_vpxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | val check_if_vpxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
let check_if_vpxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) = | false | null | false | let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs
in
let _, (o2, (o3, ())) = oprs in
if o2 = o3
then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else check_if_instr_consumes_fixed_time ins ts | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opXmm",
"Prims.Nil",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_VPxor",
"Vale.X64.Machine_s.operand128",
"Prims.op_Equality",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.Arch.HeapTypes_s.Public",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOpXmm",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotateVPxor",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins)) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_vpxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_vpxor_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 45,
"end_line": 571,
"start_col": 3,
"start_line": 559
} |
Prims.Pure | val check_if_xor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | val check_if_xor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
let check_if_xor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) = | false | null | false | let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs
in
let o1, (o2, ()) = oprs in
if o1 = o2
then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else check_if_instr_consumes_fixed_time ins ts | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.op64",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opFlagsCf",
"Vale.X64.Instruction_s.opFlagsOf",
"Prims.Nil",
"Vale.X64.Instruction_s.HavocFlags",
"Vale.X64.Instructions_s.ins_Xor64",
"Vale.X64.Machine_s.operand64",
"Prims.op_Equality",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.Arch.HeapTypes_s.Public",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.InOut",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOp64",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpIm",
"Vale.X64.Instruction_s.IOpFlagsCf",
"Vale.X64.Instruction_s.IOpFlagsOf",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotateXor64",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins)) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_xor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_xor_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 45,
"end_line": 537,
"start_col": 3,
"start_line": 525
} |
Prims.Tot | val check_if_consumes_fixed_time_outs_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t_out: taint)
: bool | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out | val check_if_consumes_fixed_time_outs_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t_out: taint)
: bool
let check_if_consumes_fixed_time_outs_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t_out: taint)
: bool = | false | null | false | match i with
| IOp64 ->
operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm ->
operand_does_not_use_secrets #quad32 #reg_xmm o ts &&
operand_taint_allowed #quad32 #reg_xmm o t_out | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Prims.op_AmpAmp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Leakage_Helpers.operand_taint_allowed",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Prims.bool"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool | false | false | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val check_if_consumes_fixed_time_outs_explicit
(i: instr_operand_explicit)
(o: instr_operand_t i)
(ts: analysis_taints)
(t_out: taint)
: bool | [] | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_explicit | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Vale.X64.Instruction_s.instr_operand_explicit ->
o: Vale.X64.Instruction_s.instr_operand_t i ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint
-> Prims.bool | {
"end_col": 114,
"end_line": 64,
"start_col": 2,
"start_line": 62
} |
Prims.Tot | val check_if_consumes_fixed_time_outs_implicit
(i: instr_operand_implicit)
(ts: analysis_taints)
(t_out: taint)
: bool | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true | val check_if_consumes_fixed_time_outs_implicit
(i: instr_operand_implicit)
(ts: analysis_taints)
(t_out: taint)
: bool
let check_if_consumes_fixed_time_outs_implicit
(i: instr_operand_implicit)
(ts: analysis_taints)
(t_out: taint)
: bool = | false | null | false | match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_s.operand64",
"Prims.op_AmpAmp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Leakage_Helpers.operand_taint_allowed",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"Prims.bool"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool | false | true | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val check_if_consumes_fixed_time_outs_implicit
(i: instr_operand_implicit)
(ts: analysis_taints)
(t_out: taint)
: bool | [] | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_implicit | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Vale.X64.Instruction_s.instr_operand_implicit ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint
-> Prims.bool | {
"end_col": 22,
"end_line": 74,
"start_col": 2,
"start_line": 70
} |
Prims.Tot | val instr_set_taint_implicit (i: instr_operand_implicit) (ts: analysis_taints) (t: taint)
: analysis_taints | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t | val instr_set_taint_implicit (i: instr_operand_implicit) (ts: analysis_taints) (t: taint)
: analysis_taints
let instr_set_taint_implicit (i: instr_operand_implicit) (ts: analysis_taints) (t: taint)
: analysis_taints = | false | null | false | match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Leakage_Helpers.set_taint",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Leakage_Helpers.set_taint_cf_and_flags",
"Vale.X64.Leakage_Helpers.set_taint_of_and_flags"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr] | false | true | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val instr_set_taint_implicit (i: instr_operand_implicit) (ts: analysis_taints) (t: taint)
: analysis_taints | [] | Vale.X64.Leakage_Ins.instr_set_taint_implicit | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Vale.X64.Instruction_s.instr_operand_implicit ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Leakage_Helpers.analysis_taints | {
"end_col": 45,
"end_line": 211,
"start_col": 2,
"start_line": 207
} |
Prims.Pure | val check_if_pxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts | val check_if_pxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
let check_if_pxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) = | false | null | false | let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs
in
let o1, (o2, ()) = oprs in
if o1 = o2
then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else check_if_instr_consumes_fixed_time ins ts | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.opXmm",
"Prims.Nil",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Machine_s.operand128",
"Prims.op_Equality",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.Arch.HeapTypes_s.Public",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.InOut",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOpXmm",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotatePxor",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins)) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_pxor_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 45,
"end_line": 554,
"start_col": 3,
"start_line": 542
} |
Prims.Tot | val instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t: taint)
: analysis_taints | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
) | val instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t: taint)
: analysis_taints
let rec instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t: taint)
: analysis_taints = | false | null | false | match outs with
| [] -> ts
| (_, i) :: outs ->
(match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"total"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Leakage_Ins.instr_set_taints",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Ins.instr_set_taint_explicit",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Ins.instr_set_taint_implicit"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t: taint)
: analysis_taints | [
"recursion"
] | Vale.X64.Leakage_Ins.instr_set_taints | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t: Vale.Arch.HeapTypes_s.taint
-> Vale.X64.Leakage_Helpers.analysis_taints | {
"end_col": 5,
"end_line": 226,
"start_col": 2,
"start_line": 217
} |
Prims.Pure | val check_if_instr_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t) | val check_if_instr_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
let check_if_instr_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts) = | false | null | false | let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> flags
in
let cf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> cf
in
let ovf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> ovf
in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"Vale.Arch.HeapTypes_s.Secret",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_Helpers.inouts_taint",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_instr_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 43,
"end_line": 518,
"start_col": 3,
"start_line": 509
} |
FStar.Pervasives.Lemma | val lemma_instr_write_outputs_ok
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: S.machine_state)
: Lemma (requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
) | val lemma_instr_write_outputs_ok
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: S.machine_state)
: Lemma (requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
let rec lemma_instr_write_outputs_ok
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: S.machine_state)
: Lemma (requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok) = | false | null | true | match outs with
| [] -> ()
| (_, i) :: outs ->
(let (v: instr_val_t i), (vs: instr_ret_t outs) =
match outs with
| [] -> (vs, ())
| _ :: _ ->
let vs = coerce vs in
(fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s') | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Leakage_Ins.lemma_instr_write_outputs_ok",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Machine_Semantics_s.instr_write_output_explicit",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_Semantics_s.instr_write_output_implicit",
"Prims.unit",
"FStar.Pervasives.Native.Mktuple2",
"Prims.b2t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_instr_write_outputs_ok
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: S.machine_state)
: Lemma (requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok) | [
"recursion"
] | Vale.X64.Leakage_Ins.lemma_instr_write_outputs_ok | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
vs: Vale.X64.Instruction_s.instr_ret_t outs ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
s_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.instr_write_outputs outs
args
vs
oprs
s_orig
s)) (ensures Mkmachine_state?.ms_ok s) | {
"end_col": 5,
"end_line": 252,
"start_col": 2,
"start_line": 235
} |
FStar.Pervasives.Lemma | val lemma_ins_leakage_free (ts:analysis_taints) (ins:Vale.X64.Machine_Semantics_s.ins) : Lemma
(let (b, ts') = check_if_ins_consumes_fixed_time ins ts in
(b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_ins_leakage_free ts ins =
let (b, ts') = check_if_ins_consumes_fixed_time ins ts in
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> lemma_xor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotatePxor _) -> lemma_pxor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotateVPxor _) -> lemma_vpxor_leakage_free ts ins
| BC.Instr _ _ _ -> lemma_instr_leakage_free ts ins
| BC.Alloc _ -> ()
| BC.Dealloc _ -> lemma_dealloc_leakage_free ts ins
| BC.Push _ _ -> lemma_push_leakage_free ts ins
| BC.Pop _ _ -> lemma_pop_leakage_free ts ins | val lemma_ins_leakage_free (ts:analysis_taints) (ins:Vale.X64.Machine_Semantics_s.ins) : Lemma
(let (b, ts') = check_if_ins_consumes_fixed_time ins ts in
(b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts))
let lemma_ins_leakage_free ts ins = | false | null | true | let b, ts' = check_if_ins_consumes_fixed_time ins ts in
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> lemma_xor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotatePxor _) -> lemma_pxor_leakage_free ts ins
| BC.Instr _ _ (S.AnnotateVPxor _) -> lemma_vpxor_leakage_free ts ins
| BC.Instr _ _ _ -> lemma_instr_leakage_free ts ins
| BC.Alloc _ -> ()
| BC.Dealloc _ -> lemma_dealloc_leakage_free ts ins
| BC.Push _ _ -> lemma_push_leakage_free ts ins
| BC.Pop _ _ -> lemma_pop_leakage_free ts ins | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.bool",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Prims.Cons",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.op64",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.opFlagsCf",
"Vale.X64.Instruction_s.opFlagsOf",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.HavocFlags",
"Vale.X64.Instructions_s.ins_Xor64",
"Vale.X64.Leakage_Ins.lemma_xor_leakage_free",
"Vale.X64.Instruction_s.opXmm",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Leakage_Ins.lemma_pxor_leakage_free",
"Vale.X64.Instructions_s.ins_VPxor",
"Vale.X64.Leakage_Ins.lemma_vpxor_leakage_free",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Ins.lemma_instr_leakage_free",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Leakage_Ins.lemma_dealloc_leakage_free",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Ins.lemma_push_leakage_free",
"Vale.X64.Leakage_Ins.lemma_pop_leakage_free",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time",
"Vale.X64.Leakage_Ins.check_if_ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
)
let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x:int) : Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x)
=
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in Classical.forall_intro (Classical.move_requires aux)
in
()
)
let lemma_push_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Push? ins)
(ensures (
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let ptr1 = S.eval_reg_64 rRsp s1 - 8 in
let ptr2 = S.eval_reg_64 rRsp s2 - 8 in
let v1 = S.eval_operand src s1 in
let v2 = S.eval_operand src s2 in
assert (ptr1 == ptr2);
if t_out = Secret then ()
else (
let aux () : Lemma (v1 == v2)
= match src with
| OConst _ | OReg _ -> ()
| OMem (_, _) | OStack (_, _) -> S.get_heap_val64_reveal ()
in
aux()
)
in
()
)
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_pop_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Pop? ins)
(ensures (
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
allow_inversion maddr;
allow_inversion tmaddr;
let BC.Pop dst t_stk = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let stack_op = OStack (MReg reg_Rsp 0, Public) in
let v1 = S.eval_operand stack_op s1 in
let v2 = S.eval_operand stack_op s2 in
if t_stk = Public then (
S.get_heap_val64_reveal ();
assert (v1 == v2)
);
Classical.forall_intro_3 (fun s x (stack1:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro_3 (fun s x (stack2:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in
()
)
#reset-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 4 --max_fuel 4 --z3rlimit 40"
let lemma_xor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_xor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
FStar.Classical.forall_intro_with_pat (fun n -> Vale.Def.Types_s.ixor n n) Vale.Arch.Types.lemma_BitwiseXorCancel64
else
lemma_instr_leakage_free ts ins
let lemma_pxor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
Vale.Arch.Types.lemma_quad32_xor()
else
lemma_instr_leakage_free ts ins
let lemma_vpxor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_vpxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o1, (o2, ()))) = oprs in
if o1 = o2 then
Vale.Arch.Types.lemma_quad32_xor()
else
lemma_instr_leakage_free ts ins
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 20" | false | false | Vale.X64.Leakage_Ins.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_ins_leakage_free (ts:analysis_taints) (ins:Vale.X64.Machine_Semantics_s.ins) : Lemma
(let (b, ts') = check_if_ins_consumes_fixed_time ins ts in
(b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [] | Vale.X64.Leakage_Ins.lemma_ins_leakage_free | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_ins_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | {
"end_col": 47,
"end_line": 842,
"start_col": 35,
"start_line": 832
} |
Prims.Pure | val check_if_consumes_fixed_time_args
(args: list instr_operand)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2)) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b'' | val check_if_consumes_fixed_time_args
(args: list instr_operand)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
let rec check_if_consumes_fixed_time_args
(args: list instr_operand)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2)) = | false | null | false | allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| IOpEx i :: args ->
let (o: instr_operand_t i), (oprs: instr_operands_t_args args) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| IOpIm i :: args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b'' | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t_args",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Prims.op_AmpAmp",
"Prims.bool",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Machine_s.quad32",
"Vale.X64.Machine_s.reg_xmm",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.operand128",
"Prims.unit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_True",
"Prims.l_imp",
"Prims.b2t",
"Prims.l_Forall",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.eq2",
"Vale.X64.Machine_s.observation",
"Vale.X64.Leakage_Ins.obs_args"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2)) | false | false | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val check_if_consumes_fixed_time_args
(args: list instr_operand)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2)) | [
"recursion"
] | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure Prims.bool | {
"end_col": 13,
"end_line": 55,
"start_col": 2,
"start_line": 33
} |
Prims.Pure | val check_if_pop_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Pop? ins) (ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk) | val check_if_pop_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Pop? ins) (ensures ins_consumes_fixed_time ins ts)
let check_if_pop_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Pop? ins) (ensures ins_consumes_fixed_time ins ts) = | false | null | false | let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed,
set_taint 0 dst ts t_stk) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Prims.op_AmpAmp",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.Lib.MapTree.sel",
"Vale.X64.Machine_s.reg",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__rts",
"Vale.X64.Machine_s.reg_Rsp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Vale.X64.Leakage_Helpers.set_taint",
"Vale.X64.Leakage_Helpers.operand_taint_allowed",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Pop",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins) | false | false | Vale.X64.Leakage_Ins.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 4,
"initial_ifuel": 3,
"max_fuel": 4,
"max_ifuel": 3,
"no_plugins": false,
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_pop_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Pop? ins) (ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_pop_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 125,
"end_line": 601,
"start_col": 3,
"start_line": 598
} |
Prims.Pure | val check_if_push_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Push? ins) (ensures ins_consumes_fixed_time ins ts) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts) | val check_if_push_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Push? ins) (ensures ins_consumes_fixed_time ins ts)
let check_if_push_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Push? ins) (ensures ins_consumes_fixed_time ins ts) = | false | null | false | let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts &&
(t_out = Public || t_stk = Secret),
ts) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Prims.op_AmpAmp",
"Vale.Arch.HeapTypes_s.uu___is_Public",
"Vale.Lib.MapTree.sel",
"Vale.X64.Machine_s.reg",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__rts",
"Vale.X64.Machine_s.reg_Rsp",
"Vale.X64.Leakage_Helpers.operand_does_not_use_secrets",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Prims.op_BarBar",
"Prims.op_Equality",
"Vale.Arch.HeapTypes_s.Public",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Leakage_Helpers.operand_taint",
"FStar.Pervasives.Native.tuple2",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Push",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Leakage_Helpers.ins_consumes_fixed_time"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins) | false | false | Vale.X64.Leakage_Ins.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 4,
"initial_ifuel": 3,
"max_fuel": 4,
"max_ifuel": 3,
"no_plugins": false,
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val check_if_push_consumes_fixed_time (ins: S.ins) (ts: analysis_taints)
: Pure (bool & analysis_taints) (requires BC.Push? ins) (ensures ins_consumes_fixed_time ins ts) | [] | Vale.X64.Leakage_Ins.check_if_push_consumes_fixed_time | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ins: Vale.X64.Machine_Semantics_s.ins -> ts: Vale.X64.Leakage_Helpers.analysis_taints
-> Prims.Pure (Prims.bool * Vale.X64.Leakage_Helpers.analysis_taints) | {
"end_col": 130,
"end_line": 593,
"start_col": 3,
"start_line": 590
} |
Prims.Pure | val check_if_consumes_fixed_time_outs
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t_out: taint)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==>
obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2)) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b'' | val check_if_consumes_fixed_time_outs
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t_out: taint)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==>
obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
let rec check_if_consumes_fixed_time_outs
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t_out: taint)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==>
obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2)) = | false | null | false | allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i) :: outs ->
let (o: instr_operand_t i), (oprs: instr_operands_t outs args) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i) :: outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b'' | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Prims.op_AmpAmp",
"Prims.bool",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_explicit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs_implicit",
"Prims.unit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_True",
"Prims.l_imp",
"Prims.b2t",
"Prims.l_Forall",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.eq2",
"Vale.X64.Machine_s.observation",
"Vale.X64.Leakage_Ins.obs_inouts"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2)) | false | false | Vale.X64.Leakage_Ins.fst | {
"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"
} | null | val check_if_consumes_fixed_time_outs
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
(ts: analysis_taints)
(t_out: taint)
: Pure bool
(requires True)
(ensures
fun b ->
b ==>
(forall (s1: S.machine_state) (s2: S.machine_state).
{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==>
obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2)) | [
"recursion"
] | Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint
-> Prims.Pure Prims.bool | {
"end_col": 13,
"end_line": 98,
"start_col": 2,
"start_line": 84
} |
FStar.Pervasives.Lemma | val lemma_instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(vs1 vs2: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(ts_orig ts: analysis_taints)
(t_out: taint)
(s1_orig s1 s2_orig s2: S.machine_state)
: Lemma
(requires
(let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\ (t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\ publicValuesAreSame ts.lts s1 s2))
(ensures
(let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2')) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
) | val lemma_instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(vs1 vs2: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(ts_orig ts: analysis_taints)
(t_out: taint)
(s1_orig s1 s2_orig s2: S.machine_state)
: Lemma
(requires
(let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\ (t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\ publicValuesAreSame ts.lts s1 s2))
(ensures
(let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'))
let rec lemma_instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(vs1 vs2: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(ts_orig ts: analysis_taints)
(t_out: taint)
(s1_orig s1 s2_orig s2: S.machine_state)
: Lemma
(requires
(let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\ (t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\ publicValuesAreSame ts.lts s1 s2))
(ensures
(let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2')) = | false | null | true | match outs with
| [] -> ()
| (_, i) :: outs ->
(let (v1: instr_val_t i), (vs1: instr_ret_t outs) =
match outs with
| [] -> (vs1, ())
| _ :: _ ->
let vs1 = coerce vs1 in
(fst vs1, snd vs1)
in
let (v2: instr_val_t i), (vs2: instr_ret_t outs) =
match outs with
| [] -> (vs2, ())
| _ :: _ ->
let vs2 = coerce vs2 in
(fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let o, oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig
s2') | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints",
"Prims.unit",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints_explicit",
"Vale.X64.Leakage_Ins.instr_set_taint_explicit",
"Vale.X64.Leakage_Ins.lemma_instr_write_outputs_ok",
"Vale.X64.Machine_Semantics_s.instr_write_output_explicit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints_implicit",
"Vale.X64.Leakage_Ins.instr_set_taint_implicit",
"Vale.X64.Machine_Semantics_s.instr_write_output_implicit",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Prims.l_imp",
"Prims.eq2",
"Vale.Arch.HeapTypes_s.Public",
"FStar.Set.equal",
"Prims.int",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Arch.Heap.heap_get",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.X64.Leakage_s.publicValuesAreSame",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"Prims.squash",
"Vale.X64.Leakage_Ins.instr_set_taints",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
)) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_instr_set_taints
(outs: list instr_out)
(args: list instr_operand)
(vs1 vs2: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(ts_orig ts: analysis_taints)
(t_out: taint)
(s1_orig s1 s2_orig s2: S.machine_state)
: Lemma
(requires
(let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\ (t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\ publicValuesAreSame ts.lts s1 s2))
(ensures
(let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2')) | [
"recursion"
] | Vale.X64.Leakage_Ins.lemma_instr_set_taints | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
vs1: Vale.X64.Instruction_s.instr_ret_t outs ->
vs2: Vale.X64.Instruction_s.instr_ret_t outs ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
ts_orig: Vale.X64.Leakage_Helpers.analysis_taints ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
t_out: Vale.Arch.HeapTypes_s.taint ->
s1_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let s1_state' =
Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs1 oprs s1_orig s1
in
let s2_state' =
Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs2 oprs s2_orig s2
in
Mkmachine_state?.ms_ok s1_state' /\ Mkmachine_state?.ms_ok s2_state' /\
(t_out == Vale.Arch.HeapTypes_s.Public ==> vs1 == vs2) /\
FStar.Set.equal (FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s1_orig
)))
(FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s1))) /\
FStar.Set.equal (FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s2_orig
)))
(FStar.Map.domain (Vale.Arch.Heap.heap_get (Mkmachine_state?.ms_heap s2))) /\
Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
Vale.X64.Leakage_s.publicValuesAreSame (AnalysisTaints?.lts ts_orig) s1_orig s2_orig /\
Vale.X64.Leakage_s.publicValuesAreSame (AnalysisTaints?.lts ts) s1 s2))
(ensures
(let s1' = Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' =
Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs2 oprs s2_orig s2
in
let ts' = Vale.X64.Leakage_Ins.instr_set_taints outs args oprs ts t_out in
Vale.X64.Leakage_s.publicValuesAreSame (AnalysisTaints?.lts ts') s1' s2')) | {
"end_col": 5,
"end_line": 504,
"start_col": 2,
"start_line": 472
} |
FStar.Pervasives.Lemma | val lemma_dealloc_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Dealloc? ins)
(ensures
(let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x:int) : Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x)
=
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in Classical.forall_intro (Classical.move_requires aux)
in
()
) | val lemma_dealloc_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Dealloc? ins)
(ensures
(let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts))
let lemma_dealloc_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Dealloc? ins)
(ensures
(let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) = | false | null | true | let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
if b
then
(let code = Ins ins in
let lem (s1 s2: S.machine_state) (fuel: nat)
: Lemma (requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)] =
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x: int)
: Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures
publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x) =
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in
Classical.forall_intro (Classical.move_requires aux)
in
()) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.nat",
"Prims.unit",
"Vale.X64.Leakage_s.is_explicit_leakage_free_lhs",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.squash",
"Vale.X64.Leakage_s.is_explicit_leakage_free_rhs",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil",
"Vale.X64.Machine_s.nat64",
"Vale.Def.Types_s.nat64",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Map.t",
"Prims.int",
"Vale.Def.Types_s.nat8",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Vale.X64.Leakage_s.publicStackValueIsSame",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"FStar.Classical.move_requires",
"FStar.Set.set",
"Prims.eq2",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"FStar.Map.restrict",
"Vale.Lib.Set.lemma_sel_restrict",
"Vale.X64.Machine_Semantics_s.machine_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Leakage_Ins.machine_eval_code",
"Vale.X64.Machine_s.precode",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Machine_s.Ins",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time",
"Vale.X64.Bytes_Code_s.uu___is_Dealloc",
"Prims.l_and",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Leakage_s.isLeakageFree"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
)
let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts | false | false | Vale.X64.Leakage_Ins.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_dealloc_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Dealloc? ins)
(ensures
(let b, ts' = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [] | Vale.X64.Leakage_Ins.lemma_dealloc_leakage_free | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Dealloc? ins)
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_dealloc_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | {
"end_col": 3,
"end_line": 702,
"start_col": 3,
"start_line": 676
} |
FStar.Pervasives.Lemma | val lemma_instr_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins)
(ensures
(let b, ts' = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
) | val lemma_instr_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins)
(ensures
(let b, ts' = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts))
let lemma_instr_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins)
(ensures
(let b, ts' = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) = | false | null | true | let b, ts' = check_if_instr_consumes_fixed_time ins ts in
if b
then
(let code = Ins ins in
let lem (s1 s2: S.machine_state) (fuel: nat)
: Lemma (requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)] =
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = { s1 with S.ms_trace = [] } in
let s2 = { s2 with S.ms_trace = [] } in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> { s1 with S.ms_flags = S.havoc_flags }
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> { s2 with S.ms_flags = S.havoc_flags }
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> flags
in
let cf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> cf
in
let ovf =
match havoc_flags with
| HavocFlags -> Secret
| PreserveFlags -> ovf
in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret
then
(lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
())
else
(let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
())
in
()) | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.nat",
"Prims.unit",
"Vale.X64.Leakage_s.is_explicit_leakage_free_lhs",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.squash",
"Vale.X64.Leakage_s.is_explicit_leakage_free_rhs",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.logical",
"Prims.Nil",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Leakage_s.reg_taint",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.regmap",
"Vale.X64.Leakage_Helpers.is_map_of",
"Vale.X64.Leakage_s.__proj__LeakageTaints__item__regTaint",
"Vale.X64.Leakage_s.LeakageTaints",
"Prims.op_Equality",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Leakage_Ins.lemma_instr_set_taints",
"Vale.X64.Leakage_Ins.lemma_inouts_taint",
"Vale.X64.Instruction_s.instr_eval",
"Vale.X64.Leakage_Helpers.AnalysisTaints",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Machine_Semantics_s.havoc_flags",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"FStar.Pervasives.Native.option",
"Vale.X64.Machine_Semantics_s.instr_apply_eval",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags",
"Vale.X64.Machine_s.observation",
"Vale.X64.Leakage_Helpers.inouts_taint",
"Vale.X64.Machine_s.precode",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Machine_s.Ins",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Prims.l_imp",
"Prims.l_and",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Leakage_s.isLeakageFree"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts | false | false | Vale.X64.Leakage_Ins.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_instr_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins)
(ensures
(let b, ts' = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [] | Vale.X64.Leakage_Ins.lemma_instr_leakage_free | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Instr? ins)
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_instr_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | {
"end_col": 3,
"end_line": 668,
"start_col": 3,
"start_line": 621
} |
FStar.Pervasives.Lemma | val lemma_args_taint
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\ Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\ args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 == S.instr_apply_eval_args outs args f oprs s2) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2 | val lemma_args_taint
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\ Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\ args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 == S.instr_apply_eval_args outs args f oprs s2)
let rec lemma_args_taint
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\ Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\ args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 == S.instr_apply_eval_args outs args f oprs s2) = | false | null | true | allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i :: args ->
let v1, v2, oprs:option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let o, (oprs: instr_operands_t_args args) = coerce oprs in
(S.instr_eval_operand_explicit i o s1, S.instr_eval_operand_explicit i o s2, oprs)
| IOpIm i ->
let oprs = coerce oprs in
(S.instr_eval_operand_implicit i s1, S.instr_eval_operand_implicit i s2, oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2 | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_args_t",
"Vale.X64.Instruction_s.instr_operands_t_args",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.X64.Leakage_Ins.lemma_args_taint",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val64_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val32_reveal",
"Vale.X64.Instruction_s.arrow",
"Vale.X64.Instruction_s.coerce",
"FStar.Pervasives.Native.tuple3",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.Pervasives.Native.Mktuple3",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_and",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_args",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.args_taint",
"Vale.Arch.HeapTypes_s.Public",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_args_taint
(outs: list instr_out)
(args: list instr_operand)
(f: instr_args_t outs args)
(oprs: instr_operands_t_args args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\ Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\ args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 == S.instr_apply_eval_args outs args f oprs s2) | [
"recursion"
] | Vale.X64.Leakage_Ins.lemma_args_taint | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
f: Vale.X64.Instruction_s.instr_args_t outs args ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Leakage_s.constTimeInvariant (AnalysisTaints?.lts ts) s1 s2 /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s1) /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s2) /\
Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_args args oprs ts /\
Vale.X64.Leakage_Helpers.args_taint args oprs ts == Vale.Arch.HeapTypes_s.Public)
(ensures
Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s1 ==
Vale.X64.Machine_Semantics_s.instr_apply_eval_args outs args f oprs s2) | {
"end_col": 50,
"end_line": 144,
"start_col": 2,
"start_line": 117
} |
FStar.Pervasives.Lemma | val lemma_inouts_taint
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2 | val lemma_inouts_taint
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
let rec lemma_inouts_taint
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2) = | false | null | true | allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i) :: inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i) :: inouts ->
let v1, v2, oprs:option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let o, (oprs: instr_operands_t inouts args) = coerce oprs in
let oprs = coerce oprs in
(S.instr_eval_operand_explicit i o s1, S.instr_eval_operand_explicit i o s2, oprs)
| IOpIm i ->
let oprs = coerce oprs in
(S.instr_eval_operand_implicit i s1, S.instr_eval_operand_implicit i s2, oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2 | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_inouts_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Leakage_Ins.lemma_args_taint",
"Vale.X64.Leakage_Ins.lemma_inouts_taint",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_explicit",
"FStar.Pervasives.Native.snd",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.instr_operand_implicit",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_val_t",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val64_reveal",
"Vale.Arch.MachineHeap_s.get_heap_val32_reveal",
"Vale.X64.Instruction_s.arrow",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"FStar.Pervasives.allow_inversion",
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.tmaddr",
"Vale.X64.Machine_s.maddr",
"Prims.l_and",
"Vale.X64.Leakage_s.constTimeInvariant",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts",
"Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs",
"Vale.Arch.HeapTypes_s.Public",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Leakage_Helpers.inouts_taint",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2) | false | false | Vale.X64.Leakage_Ins.fst | {
"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": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_inouts_taint
(outs inouts: list instr_out)
(args: list instr_operand)
(f: instr_inouts_t outs inouts args)
(oprs: instr_operands_t inouts args)
(ts: analysis_taints)
(s1 s2: S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2) | [
"recursion"
] | Vale.X64.Leakage_Ins.lemma_inouts_taint | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
outs: Prims.list Vale.X64.Instruction_s.instr_out ->
inouts: Prims.list Vale.X64.Instruction_s.instr_out ->
args: Prims.list Vale.X64.Instruction_s.instr_operand ->
f: Vale.X64.Instruction_s.instr_inouts_t outs inouts args ->
oprs: Vale.X64.Instruction_s.instr_operands_t inouts args ->
ts: Vale.X64.Leakage_Helpers.analysis_taints ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Leakage_s.constTimeInvariant (AnalysisTaints?.lts ts) s1 s2 /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s2) /\
Vale.X64.Leakage_Ins.check_if_consumes_fixed_time_outs inouts
args
oprs
ts
Vale.Arch.HeapTypes_s.Public /\
Vale.X64.Leakage_Helpers.inouts_taint inouts args oprs ts == Vale.Arch.HeapTypes_s.Public)
(ensures
Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s1 ==
Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts outs inouts args f oprs s2) | {
"end_col": 59,
"end_line": 196,
"start_col": 2,
"start_line": 162
} |
FStar.Pervasives.Lemma | val lemma_pxor_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures
(let b, ts' = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": "BC"
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Leakage_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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
}
] | false | let lemma_pxor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
Vale.Arch.Types.lemma_quad32_xor()
else
lemma_instr_leakage_free ts ins | val lemma_pxor_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures
(let b, ts' = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts))
let lemma_pxor_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures
(let b, ts' = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) = | false | null | true | let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs
in
let o1, (o2, ()) = oprs in
if o1 = o2 then Vale.Arch.Types.lemma_quad32_xor () else lemma_instr_leakage_free ts ins | {
"checked_file": "Vale.X64.Leakage_Ins.fst.checked",
"dependencies": [
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Leakage_s.fst.checked",
"Vale.X64.Leakage_Helpers.fst.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Lib.Set.fsti.checked",
"Vale.Lib.MapTree.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.MachineHeap_s.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Leakage_Ins.fst"
} | [
"lemma"
] | [
"Vale.X64.Leakage_Helpers.analysis_taints",
"Vale.X64.Machine_Semantics_s.ins",
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.flag_havoc",
"Vale.X64.Instruction_s.instr_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.InstrTypeRecord",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_Semantics_s.equals_instr",
"Prims.Cons",
"Vale.X64.Instruction_s.inOut",
"Vale.X64.Instruction_s.opXmm",
"Prims.Nil",
"Vale.X64.Instruction_s.PreserveFlags",
"Vale.X64.Instructions_s.ins_Pxor",
"Vale.X64.Machine_s.operand128",
"Prims.op_Equality",
"Vale.Arch.Types.lemma_quad32_xor",
"Prims.bool",
"Vale.X64.Leakage_Ins.lemma_instr_leakage_free",
"Prims.unit",
"FStar.Pervasives.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.InOut",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOpXmm",
"Vale.X64.Leakage_Ins.coerce_to_normal",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.uu___is_AnnotatePxor",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__i",
"Vale.X64.Bytes_Code_s.__proj__Instr__item__annotation",
"Prims.squash",
"Prims.l_imp",
"Vale.X64.Leakage_s.isConstantTime",
"Vale.X64.Machine_s.Ins",
"Vale.X64.Bytes_Code_s.instruction_t",
"Vale.X64.Bytes_Code_s.ocmp",
"Vale.X64.Leakage_Helpers.__proj__AnalysisTaints__item__lts",
"Vale.X64.Leakage_s.isLeakageFree",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time",
"FStar.Pervasives.pattern"
] | [] | module Vale.X64.Leakage_Ins
open FStar.Mul
open Vale.Arch.MachineHeap_s
open Vale.Arch.Heap
open Vale.X64.Machine_s
open Vale.X64.Instruction_s
module BC = Vale.X64.Bytes_Code_s
module S = Vale.X64.Machine_Semantics_s
open Vale.X64.Leakage_s
open Vale.X64.Leakage_Helpers
unfold let (.[]) = Map.sel
unfold let (.[]<-) = Map.upd
unfold let obs_args = S.obs_args
unfold let obs_inouts = S.obs_inouts
unfold let machine_eval_code = S.machine_eval_code
let reveal_machine_eval_code_ins (i:S.ins) (s:S.machine_state) : Lemma
(requires True)
(ensures S.machine_eval_code_ins i s == S.machine_eval_code_ins_def i s)
[SMTPat (S.machine_eval_code_ins i s)]
=
reveal_opaque (`%S.machine_eval_code_ins) S.machine_eval_code_ins
let rec check_if_consumes_fixed_time_args
(args:list instr_operand) (oprs:instr_operands_t_args args) (ts:analysis_taints)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_args args oprs s1 == obs_args args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
match args with
| [] -> true
| (IOpEx i)::args ->
let ((o:instr_operand_t i), (oprs:instr_operands_t_args args)) = coerce oprs in
let b' =
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts
in
let b'' = check_if_consumes_fixed_time_args args oprs ts in
b' && b''
| (IOpIm i)::args ->
let b' =
match i with
| IOp64One o -> operand_does_not_use_secrets o ts
| IOpXmmOne o -> operand_does_not_use_secrets o ts
| IOpFlagsCf -> true
| IOpFlagsOf -> true
in
let b'' = check_if_consumes_fixed_time_args args (coerce oprs) ts in
b' && b''
let check_if_consumes_fixed_time_outs_explicit
(i:instr_operand_explicit) (o:instr_operand_t i)
(ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64 -> operand_does_not_use_secrets #nat64 #reg_64 o ts && operand_taint_allowed #nat64 #reg_64 o t_out
| IOpXmm -> operand_does_not_use_secrets #quad32 #reg_xmm o ts && operand_taint_allowed #quad32 #reg_xmm o t_out
let check_if_consumes_fixed_time_outs_implicit
(i:instr_operand_implicit) (ts:analysis_taints) (t_out:taint)
: bool
=
match i with
| IOp64One o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpXmmOne o -> operand_does_not_use_secrets o ts && operand_taint_allowed o t_out
| IOpFlagsCf -> true
| IOpFlagsOf -> true
let rec check_if_consumes_fixed_time_outs
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args)
(ts:analysis_taints) (t_out:taint)
: Pure bool
(requires True)
(ensures fun b -> b ==> (forall (s1 s2:S.machine_state).{:pattern (constTimeInvariant ts.lts s1 s2)}
constTimeInvariant ts.lts s1 s2 ==> obs_inouts outs args oprs s1 == obs_inouts outs args oprs s2))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match outs with
| [] -> check_if_consumes_fixed_time_args args oprs ts
| (_, IOpEx i)::outs ->
let ((o:instr_operand_t i), (oprs:instr_operands_t outs args)) = coerce oprs in
let b' = check_if_consumes_fixed_time_outs_explicit i o ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args oprs ts t_out in
b' && b''
| (_, IOpIm i)::outs ->
let b' = check_if_consumes_fixed_time_outs_implicit i ts t_out in
let b'' = check_if_consumes_fixed_time_outs outs args (coerce oprs) ts t_out in
b' && b''
#restart-solver
#reset-options "--z3rlimit 300"
let rec lemma_args_taint
(outs:list instr_out) (args:list instr_operand)
(f:instr_args_t outs args) (oprs:instr_operands_t_args args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_args outs args f oprs s1) /\
Some? (S.instr_apply_eval_args outs args f oprs s2) /\
check_if_consumes_fixed_time_args args oprs ts /\
args_taint args oprs ts == Public)
(ensures
S.instr_apply_eval_args outs args f oprs s1 ==
S.instr_apply_eval_args outs args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match args with
| [] -> ()
| i::args ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t_args args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t_args args)) = coerce oprs in
(
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_args_taint outs args (f v) oprs ts s1 s2
#restart-solver
let rec lemma_inouts_taint
(outs inouts:list instr_out) (args:list instr_operand)
(f:instr_inouts_t outs inouts args) (oprs:instr_operands_t inouts args)
(ts:analysis_taints) (s1 s2:S.machine_state)
: Lemma
(requires
constTimeInvariant ts.lts s1 s2 /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s1) /\
Some? (S.instr_apply_eval_inouts outs inouts args f oprs s2) /\
check_if_consumes_fixed_time_outs inouts args oprs ts Public /\
inouts_taint inouts args oprs ts == Public)
(ensures
S.instr_apply_eval_inouts outs inouts args f oprs s1 ==
S.instr_apply_eval_inouts outs inouts args f oprs s2)
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
match inouts with
| [] -> lemma_args_taint outs args f oprs ts s1 s2
| (Out, i)::inouts ->
let oprs =
match i with
| IOpEx i -> snd #(instr_operand_t i) (coerce oprs)
| IOpIm i -> coerce oprs
in
lemma_inouts_taint outs inouts args (coerce f) oprs ts s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option (instr_val_t i) & option (instr_val_t i) & instr_operands_t inouts args =
match i with
| IOpEx i ->
let (o, (oprs:instr_operands_t inouts args)) = coerce oprs in
let oprs = coerce oprs in (
S.instr_eval_operand_explicit i o s1,
S.instr_eval_operand_explicit i o s2,
oprs)
| IOpIm i ->
let oprs = coerce oprs in (
S.instr_eval_operand_implicit i s1,
S.instr_eval_operand_implicit i s2,
oprs)
in
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
S.get_heap_val32_reveal ();
S.get_heap_val64_reveal ();
S.get_heap_val128_reveal ();
assert (v1 == v2);
let Some v = v1 in
lemma_inouts_taint outs inouts args (f v) oprs ts s1 s2
let instr_set_taint_explicit
(i:instr_operand_explicit) (o:instr_operand_t i) (ts:analysis_taints) (t:taint)
: analysis_taints =
match i with
| IOp64 -> set_taint 0 (o <: operand64) ts t
| IOpXmm -> set_taint 1 (o <: operand128) ts t
[@instr_attr]
let instr_set_taint_implicit (i:instr_operand_implicit) (ts:analysis_taints) (t:taint) : analysis_taints =
match i with
| IOp64One o -> set_taint 0 o ts t
| IOpXmmOne o -> set_taint 1 o ts t
| IOpFlagsCf -> set_taint_cf_and_flags ts t
| IOpFlagsOf -> set_taint_of_and_flags ts t
let rec instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(oprs:instr_operands_t outs args) (ts:analysis_taints) (t:taint)
: analysis_taints =
match outs with
| [] -> ts
| (_, i)::outs ->
(
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
instr_set_taints outs args (snd oprs) (instr_set_taint_explicit i (fst oprs) ts t) t
| IOpIm i -> instr_set_taints outs args (coerce oprs) (instr_set_taint_implicit i ts t) t
)
let rec lemma_instr_write_outputs_ok
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:S.machine_state)
: Lemma
(requires (S.instr_write_outputs outs args vs oprs s_orig s).S.ms_ok)
(ensures s.S.ms_ok)
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v:instr_val_t i), (vs:instr_ret_t outs)) =
match outs with
| [] -> (vs, ())
| _::_ -> let vs = coerce vs in (fst vs, snd vs)
in
match i with
| IOpEx i ->
let oprs:instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s' = S.instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_ok outs args vs (snd oprs) s_orig s'
| IOpIm i ->
let s' = S.instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_ok outs args vs (coerce oprs) s_orig s'
)
[@"opaque_to_smt"]
let update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_four 8 v in
match (i - ptr) with
| 0 -> v.lo0
| 1 -> v.lo1
| 2 -> v.hi2
| 3 -> v.hi3
| _ -> 0
let valid_addr32 (ptr:int) (mem:S.machine_heap) : bool =
S.valid_addr (ptr + 0) mem &&
S.valid_addr (ptr + 1) mem &&
S.valid_addr (ptr + 2) mem &&
S.valid_addr (ptr + 3) mem
let lemma_update_heap32_val (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures (S.update_heap32 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 4 then update_heap32_val ptr v i else mem.[i]))
[SMTPat ((S.update_heap32 ptr v mem).[i])]
=
S.update_heap32_reveal ();
reveal_opaque (`%update_heap32_val) update_heap32_val
let lemma_update_heap32_domain (ptr:int) (v:Vale.Def.Types_s.nat32) (mem:S.machine_heap) : Lemma
(requires valid_addr32 ptr mem)
(ensures Map.domain (S.update_heap32 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap32 ptr v mem))]
=
S.update_heap32_reveal ();
assert (Set.equal (Map.domain (S.update_heap32 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap64_val (ptr:int) (v:nat64) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let open Vale.Def.Words.Two_s in
let open Vale.Def.Words.Four_s in
let v = nat_to_two 32 v in
let lo = nat_to_four 8 v.lo in
let hi = nat_to_four 8 v.hi in
match (i - ptr) with
| 0 -> lo.lo0
| 1 -> lo.lo1
| 2 -> lo.hi2
| 3 -> lo.hi3
| 4 -> hi.lo0
| 5 -> hi.lo1
| 6 -> hi.hi2
| 7 -> hi.hi3
| _ -> 0
let lemma_update_heap64_val (ptr:int) (v:nat64) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap64 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 8 then update_heap64_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap64 ptr v mem).[i])]
=
S.update_heap64_reveal ();
reveal_opaque (`%update_heap64_val) update_heap64_val
let lemma_update_heap64_domain (ptr:int) (v:nat64) (mem:S.machine_heap) : Lemma
(requires S.valid_addr64 ptr mem)
(ensures Map.domain (S.update_heap64 ptr v mem) == Map.domain mem)
[SMTPat (Map.domain (S.update_heap64 ptr v mem))]
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
S.update_heap64_reveal ();
assert (Set.equal (Map.domain (S.update_heap64 ptr v mem)) (Map.domain mem))
[@"opaque_to_smt"]
let update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (i:int) : Vale.Def.Types_s.nat8 =
let open Vale.Def.Words_s in
let j = i - ptr in
if 0 <= j && j < 4 then update_heap32_val (ptr + 0 ) v.lo0 i else
if 4 <= j && j < 8 then update_heap32_val (ptr + 4 ) v.lo1 i else
if 8 <= j && j < 12 then update_heap32_val (ptr + 8 ) v.hi2 i else
if 12 <= j && j < 16 then update_heap32_val (ptr + 12) v.hi3 i else
0
let valid_addr128 (ptr:int) (mem:S.machine_heap) : bool =
valid_addr32 (ptr + 0) mem &&
valid_addr32 (ptr + 4) mem &&
valid_addr32 (ptr + 8) mem &&
valid_addr32 (ptr + 12) mem
let lemma_update_heap128_val (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) (i:int) : Lemma
(requires True)
(ensures
(S.update_heap128 ptr v mem).[i] ==
(if ptr <= i && i < ptr + 16 then update_heap128_val ptr v i else mem.[i])
)
[SMTPat ((S.update_heap128 ptr v mem).[i])]
=
S.update_heap128_reveal ();
reveal_opaque (`%update_heap128_val) update_heap128_val
let lemma_update_heap128_domain (ptr:int) (v:Vale.Def.Types_s.quad32) (mem:S.machine_heap) : Lemma
(requires valid_addr128 ptr mem)
(ensures Map.domain (S.update_heap128 ptr v mem) == Map.domain mem)
[SMTPat (S.update_heap128 ptr v mem)]
=
S.update_heap128_reveal ();
assert (Set.equal (Map.domain (S.update_heap128 ptr v mem)) (Map.domain mem))
let lemma_preserve_valid64 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr64 i m')}
S.valid_addr64 i m ==> S.valid_addr64 i m'))
=
reveal_opaque (`%S.valid_addr64) S.valid_addr64
let lemma_preserve_valid128 (m m':S.machine_heap) : Lemma
(requires Set.equal (Map.domain m) (Map.domain m'))
(ensures (forall (i:int).{:pattern (S.valid_addr128 i m')}
S.valid_addr128 i m ==> S.valid_addr128 i m'))
=
reveal_opaque (`%S.valid_addr128) S.valid_addr128
let lemma_instr_set_taints_explicit
(i:instr_operand_explicit) (v1 v2:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_explicit i o ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
let ts' = instr_set_taint_explicit i o ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
let lemma_instr_set_taints_implicit
(i:instr_operand_implicit) (v1 v2:instr_val_t (IOpIm i))
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
s1'.S.ms_ok /\ s2'.S.ms_ok /\
(t_out == Public ==> v1 == v2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs_implicit i ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
let ts' = instr_set_taint_implicit i ts t_out in
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1'.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2'.S.ms_heap)) /\
publicValuesAreSame ts'.lts s1' s2'
))
=
allow_inversion maddr;
allow_inversion tmaddr;
allow_inversion operand64;
allow_inversion operand128;
lemma_preserve_valid64 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid64 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
lemma_preserve_valid128 (heap_get s1_orig.S.ms_heap) (heap_get s1.S.ms_heap);
lemma_preserve_valid128 (heap_get s2_orig.S.ms_heap) (heap_get s2.S.ms_heap);
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
()
#reset-options "--z3rlimit 80"
let rec lemma_instr_set_taints
(outs:list instr_out) (args:list instr_operand)
(vs1 vs2:instr_ret_t outs) (oprs:instr_operands_t outs args)
(ts_orig ts:analysis_taints) (t_out:taint)
(s1_orig s1 s2_orig s2:S.machine_state)
: Lemma
(requires (
let s1_state' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2_state' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
s1_state'.S.ms_ok /\ s2_state'.S.ms_ok /\
(t_out == Public ==> vs1 == vs2) /\
Set.equal (Map.domain (heap_get s1_orig.S.ms_heap)) (Map.domain (heap_get s1.S.ms_heap)) /\
Set.equal (Map.domain (heap_get s2_orig.S.ms_heap)) (Map.domain (heap_get s2.S.ms_heap)) /\
check_if_consumes_fixed_time_outs outs args oprs ts_orig t_out /\
publicValuesAreSame ts_orig.lts s1_orig s2_orig /\
publicValuesAreSame ts.lts s1 s2
))
(ensures (
let s1' = S.instr_write_outputs outs args vs1 oprs s1_orig s1 in
let s2' = S.instr_write_outputs outs args vs2 oprs s2_orig s2 in
let ts' = instr_set_taints outs args oprs ts t_out in
publicValuesAreSame ts'.lts s1' s2'
))
=
match outs with
| [] -> ()
| (_, i)::outs ->
(
let ((v1:instr_val_t i), (vs1:instr_ret_t outs)) =
match outs with
| [] -> (vs1, ())
| _::_ -> let vs1 = coerce vs1 in (fst vs1, snd vs1)
in
let ((v2:instr_val_t i), (vs2:instr_ret_t outs)) =
match outs with
| [] -> (vs2, ())
| _::_ -> let vs2 = coerce vs2 in (fst vs2, snd vs2)
in
match i with
| IOpEx i ->
let (o, oprs):instr_operand_t i & instr_operands_t outs args = coerce oprs in
let s1' = S.instr_write_output_explicit i v1 o s1_orig s1 in
let s2' = S.instr_write_output_explicit i v2 o s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 oprs s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 oprs s2_orig s2';
let ts' = instr_set_taint_explicit i o ts t_out in
lemma_instr_set_taints_explicit i v1 v2 o ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 oprs ts_orig ts' t_out s1_orig s1' s2_orig s2'
| IOpIm i ->
let s1' = S.instr_write_output_implicit i v1 s1_orig s1 in
let s2' = S.instr_write_output_implicit i v2 s2_orig s2 in
lemma_instr_write_outputs_ok outs args vs1 (coerce oprs) s1_orig s1';
lemma_instr_write_outputs_ok outs args vs2 (coerce oprs) s2_orig s2';
let ts' = instr_set_taint_implicit i ts t_out in
lemma_instr_set_taints_implicit i v1 v2 ts_orig ts t_out s1_orig s1 s2_orig s2;
lemma_instr_set_taints outs args vs1 vs2 (coerce oprs) ts_orig ts' t_out s1_orig s1' s2_orig s2'
)
let check_if_instr_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs _ = ins in
let t = inouts_taint outs args oprs ts in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
(b, instr_set_taints outs args oprs ts t)
let coerce_to_normal (#a:Type0) (x:a) : y:(normal a){x == y} = x
let check_if_xor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs _ _ _) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs Secret Public Public) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_pxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotatePxor eq) = ins in
let oprs:normal (instr_operands_t [inOut opXmm] [opXmm]) =
coerce_to_normal #(instr_operands_t [inOut opXmm] [opXmm]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_vpxor_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Instr? ins /\ S.AnnotateVPxor? (BC.Instr?.annotation ins))
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateVPxor eq) = ins in
let oprs:normal (instr_operands_t [out opXmm] [opXmm; opXmm]) =
coerce_to_normal #(instr_operands_t [out opXmm] [opXmm; opXmm]) oprs in
let (_, (o2, (o3, ()))) = oprs in
if o2 = o3 then
let t = Public in
let b = check_if_consumes_fixed_time_outs outs args oprs ts t in
let AnalysisTaints (LeakageTaints rs ft cft oft) rts = ts in
let ts = AnalysisTaints (LeakageTaints rs ft cft oft) rts in
(b, instr_set_taints outs args oprs ts t)
else
check_if_instr_consumes_fixed_time ins ts
let check_if_alloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Alloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
let check_if_dealloc_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Dealloc? ins)
(ensures ins_consumes_fixed_time ins ts)
=
(true, ts)
#reset-options "--initial_ifuel 3 --max_ifuel 3 --initial_fuel 4 --max_fuel 4 --z3rlimit 80"
let check_if_push_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Push? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets src ts && (t_out = Public || t_stk = Secret), ts)
let check_if_pop_consumes_fixed_time (ins:S.ins) (ts:analysis_taints) : Pure (bool & analysis_taints)
(requires BC.Pop? ins)
(ensures ins_consumes_fixed_time ins ts)
=
let BC.Pop dst t_stk = ins in
let allowed = operand_taint_allowed dst t_stk in
(Public? (Vale.Lib.MapTree.sel ts.rts reg_Rsp) && operand_does_not_use_secrets dst ts && allowed, set_taint 0 dst ts t_stk)
let check_if_ins_consumes_fixed_time ins ts =
match ins with
| BC.Instr _ _ (S.AnnotateXor64 _) -> check_if_xor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotatePxor _) -> check_if_pxor_consumes_fixed_time ins ts
| BC.Instr _ _ (S.AnnotateVPxor _) -> check_if_vpxor_consumes_fixed_time ins ts
| BC.Instr _ _ _ -> check_if_instr_consumes_fixed_time ins ts
| BC.Push _ _ -> check_if_push_consumes_fixed_time ins ts
| BC.Pop _ _ -> check_if_pop_consumes_fixed_time ins ts
| BC.Alloc _ -> check_if_alloc_consumes_fixed_time ins ts
| BC.Dealloc _ -> check_if_dealloc_consumes_fixed_time ins ts
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_instr_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins)
(ensures (
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_instr_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags i) oprs _ = ins in
let t_out = inouts_taint outs args oprs ts in
let s1 = {s1 with S.ms_trace = []} in
let s2 = {s2 with S.ms_trace = []} in
let Some vs1 = S.instr_apply_eval outs args (instr_eval i) oprs s1 in
let Some vs2 = S.instr_apply_eval outs args (instr_eval i) oprs s2 in
let s1' =
match havoc_flags with
| HavocFlags -> {s1 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s1
in
let s2' =
match havoc_flags with
| HavocFlags -> {s2 with S.ms_flags = S.havoc_flags}
| PreserveFlags -> s2
in
let AnalysisTaints (LeakageTaints rs flags cf ovf) rts = ts in
let flags = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> flags in
let cf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> cf in
let ovf = match havoc_flags with | HavocFlags -> Secret | PreserveFlags -> ovf in
let ts_havoc = AnalysisTaints (LeakageTaints rs flags cf ovf) rts in
if t_out = Secret then
(
lemma_instr_set_taints outs args vs1 vs2 oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
else
(
let vs = vs1 in
lemma_inouts_taint outs outs args (instr_eval i) oprs ts s1 s2;
lemma_instr_set_taints outs args vs vs oprs ts ts_havoc t_out s1 s1' s2 s2';
()
)
in
// assert (isExplicitLeakageFree (Ins ins) ts ts');
()
)
let lemma_dealloc_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Dealloc? ins)
(ensures (
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_dealloc_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Dealloc n = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let aux (x:int) : Lemma
(requires publicStackValueIsSame stack1 stack2 s1.S.ms_stackTaint s2.S.ms_stackTaint x)
(ensures publicStackValueIsSame stack1' stack2' s1'.S.ms_stackTaint s2'.S.ms_stackTaint x)
=
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro (fun s -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in Classical.forall_intro (Classical.move_requires aux)
in
()
)
let lemma_push_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Push? ins)
(ensures (
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_push_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
let BC.Push src t_stk = ins in
let t_out = operand_taint 0 src ts in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let S.Machine_stack _ stack1 = s1.S.ms_stack in
let S.Machine_stack _ stack2 = s2.S.ms_stack in
let S.Machine_stack _ stack1' = s1'.S.ms_stack in
let S.Machine_stack _ stack2' = s2'.S.ms_stack in
let ptr1 = S.eval_reg_64 rRsp s1 - 8 in
let ptr2 = S.eval_reg_64 rRsp s2 - 8 in
let v1 = S.eval_operand src s1 in
let v2 = S.eval_operand src s2 in
assert (ptr1 == ptr2);
if t_out = Secret then ()
else (
let aux () : Lemma (v1 == v2)
= match src with
| OConst _ | OReg _ -> ()
| OMem (_, _) | OStack (_, _) -> S.get_heap_val64_reveal ()
in
aux()
)
in
()
)
#reset-options "--initial_ifuel 1 --max_ifuel 1 --initial_fuel 1 --max_fuel 1 --z3rlimit 100"
let lemma_pop_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Pop? ins)
(ensures (
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let (b, ts') = check_if_pop_consumes_fixed_time ins ts in
if b then
(
let code = Ins ins in
let lem (s1 s2:S.machine_state) (fuel:nat) : Lemma
(requires is_explicit_leakage_free_lhs code fuel ts.lts ts'.lts s1 s2)
(ensures is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)
[SMTPat (is_explicit_leakage_free_rhs code fuel ts.lts ts'.lts s1 s2)]
=
allow_inversion maddr;
allow_inversion tmaddr;
let BC.Pop dst t_stk = ins in
let s1' = Some?.v (machine_eval_code code fuel s1) in
let s2' = Some?.v (machine_eval_code code fuel s2) in
let stack_op = OStack (MReg reg_Rsp 0, Public) in
let v1 = S.eval_operand stack_op s1 in
let v2 = S.eval_operand stack_op s2 in
if t_stk = Public then (
S.get_heap_val64_reveal ();
assert (v1 == v2)
);
Classical.forall_intro_3 (fun s x (stack1:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack1 x);
Classical.forall_intro_3 (fun s x (stack2:S.machine_heap) -> Vale.Lib.Set.lemma_sel_restrict s stack2 x)
in
()
)
#reset-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 4 --max_fuel 4 --z3rlimit 40"
let lemma_xor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotateXor64? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_xor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts
))
=
let BC.Instr (InstrTypeRecord #outs #args #havoc_flags iins) oprs (S.AnnotateXor64 eq) = ins in
let oprs:normal (instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) =
coerce_to_normal #(instr_operands_t [inOut op64; out opFlagsCf; out opFlagsOf] [op64]) oprs in
let (o1, (o2, ())) = oprs in
if o1 = o2 then
FStar.Classical.forall_intro_with_pat (fun n -> Vale.Def.Types_s.ixor n n) Vale.Arch.Types.lemma_BitwiseXorCancel64
else
lemma_instr_leakage_free ts ins
let lemma_pxor_leakage_free (ts:analysis_taints) (ins:S.ins) : Lemma
(requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures (
let (b, ts') = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts | false | false | Vale.X64.Leakage_Ins.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 4,
"initial_ifuel": 2,
"max_fuel": 4,
"max_ifuel": 2,
"no_plugins": false,
"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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pxor_leakage_free (ts: analysis_taints) (ins: S.ins)
: Lemma (requires BC.Instr? ins /\ S.AnnotatePxor? (BC.Instr?.annotation ins))
(ensures
(let b, ts' = check_if_pxor_consumes_fixed_time ins ts in
b2t b ==> isConstantTime (Ins ins) ts.lts /\ isLeakageFree (Ins ins) ts.lts ts'.lts)) | [] | Vale.X64.Leakage_Ins.lemma_pxor_leakage_free | {
"file_name": "vale/code/arch/x64/Vale.X64.Leakage_Ins.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ts: Vale.X64.Leakage_Helpers.analysis_taints -> ins: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Instr? ins /\ AnnotatePxor? (Instr?.annotation ins))
(ensures
(let _ = Vale.X64.Leakage_Ins.check_if_pxor_consumes_fixed_time ins ts in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b ts' = _ in
b ==>
Vale.X64.Leakage_s.isConstantTime (Vale.X64.Machine_s.Ins ins) (AnalysisTaints?.lts ts) /\
Vale.X64.Leakage_s.isLeakageFree (Vale.X64.Machine_s.Ins ins)
(AnalysisTaints?.lts ts)
(AnalysisTaints?.lts ts'))
<:
Type0)) | {
"end_col": 35,
"end_line": 812,
"start_col": 3,
"start_line": 804
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.